Livog
Livog
Explore posts from servers
BABetter Auth
Created by Livog on 2/26/2025 in #help
How do I control what data goes into .session_data cookie
Found the solution:
hooks: {
after: createAuthMiddleware(async (ctx) => {
const newSession = ctx.context?.newSession
if (!ctx.context.newSession) return

if (newSession && newSession.user) {
const config = await payloadConfig
const userCollection = config.collections.find((c) => Boolean(c.auth))

if (!userCollection) {
throw new Error('User collection not found')
}

const filteredUser = getFieldsToSign({
collectionConfig: userCollection,
email: newSession.user.email,
// @ts-ignore
user: newSession.user
})

const filteredSessionData = {
...newSession,
user: filteredUser
}
await setCookieCache(ctx, filteredSessionData as any)
}
})
},
hooks: {
after: createAuthMiddleware(async (ctx) => {
const newSession = ctx.context?.newSession
if (!ctx.context.newSession) return

if (newSession && newSession.user) {
const config = await payloadConfig
const userCollection = config.collections.find((c) => Boolean(c.auth))

if (!userCollection) {
throw new Error('User collection not found')
}

const filteredUser = getFieldsToSign({
collectionConfig: userCollection,
email: newSession.user.email,
// @ts-ignore
user: newSession.user
})

const filteredSessionData = {
...newSession,
user: filteredUser
}
await setCookieCache(ctx, filteredSessionData as any)
}
})
},
3 replies
BABetter Auth
Created by Livog on 2/26/2025 in #help
How do I control what data goes into .session_data cookie
I've written a custom adapter for Payload CMS which works great (as far as I tested), so if I need to I could fix it at that level if possible.
3 replies
DTDrizzle Team
Created by Livog on 7/13/2023 in #help
Foreign Key Reference to auth Schema Not Generated in Code
I was using drizzle-orm: 0.27.2 and drizzle-kit: 0.19.4
3 replies