Addition field not returned

I added a role field to the user schema but for some reason, it's not getting returned after calling the sign-in api endpoint. Here is my auth.ts. I know that I'm not supposed to add the role to the session conventionally but I did it so that I don't hit the database for role checks. I need the user sign-in endpoint to include the role field. export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, }, user: { additionalFields: { role: { type: "string", required: true, defaultValue: "customer", input: true, }, }, }, session: { additionalFields: { role: { type: "string", required: true, input: true, }, }, }, databaseHooks: { session: { create: { before: async (session) => { // Query the user's role from the database using Drizzle const user = await db.query.user.findFirst({ where: (users, { eq }) => eq(users.id, session.userId), columns: { role: true, }, }); return { data: { ...session, role: user?.role || "customer", }, }; }, }, }, }, secondaryStorage: { get: async (key) => { const value = await redis.get(key); return value ?? null; }, set: async (key, value, ttl) => { if (ttl) { await redis.set(key, value, "EX", ttl); } else { await redis.set(key, value); } }, delete: async (key) => { await redis.del(key); }, }, advanced: { cookies: { session_token: { name: "sessionId", }, }, }, });
6 Replies
iatomic.btc
iatomic.btc4mo ago
Try adding a returned field to the role and making it true
maxkabechani
maxkabechaniOP4mo ago
Just tried that, did not work
Phuni
Phuni3mo ago
Did you solve it?
Ping
Ping3mo ago
We don't allow for customizing how sign-in or sign-up endpoint returns data as of now.
mehedi1097
mehedi10973mo ago
We need it. What can we do in this case?
Ping
Ping3mo ago
Make an additional fetch.

Did you find this page helpful?