bitangel84
bitangel84
BABetter Auth
Created by bitangel84 on 3/1/2025 in #help
Update session on hooks
I've found the issue... 1. Use ctx.context.newSession 2. Use newSession.session.token to update the session this is the code that works
hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/callback/:id') {
if (ctx.params?.id === 'google') {
console.log('google callback, attaching wallet....')

const newSession = ctx.context.newSession
if (newSession?.session?.token === undefined) {
console.log('no session found')
return
}

console.log('session is', newSession)

await ctx.context.internalAdapter.updateSession(
newSession.session.token,
{
selectedWallet: 'test',
},
)

console.log('session updated')
}
}
}),
},
hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/callback/:id') {
if (ctx.params?.id === 'google') {
console.log('google callback, attaching wallet....')

const newSession = ctx.context.newSession
if (newSession?.session?.token === undefined) {
console.log('no session found')
return
}

console.log('session is', newSession)

await ctx.context.internalAdapter.updateSession(
newSession.session.token,
{
selectedWallet: 'test',
},
)

console.log('session updated')
}
}
}),
},
5 replies
BABetter Auth
Created by bitangel84 on 3/1/2025 in #help
Update session on hooks
newSession works, but I'm not able to update the session
hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/callback/:id') {
if (ctx.params?.id === 'google') {
console.log('google callback, attaching wallet....')

const newSession = ctx.context.newSession
if (newSession?.session?.id === undefined) {
console.log('no session found')
return
}

console.log('session is', newSession)

await ctx.context.internalAdapter.updateSession(
newSession.session.id,
{
selectedWallet: 'test',
},
)

console.log('session updated')
}
}
}),
},
hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path === '/callback/:id') {
if (ctx.params?.id === 'google') {
console.log('google callback, attaching wallet....')

const newSession = ctx.context.newSession
if (newSession?.session?.id === undefined) {
console.log('no session found')
return
}

console.log('session is', newSession)

await ctx.context.internalAdapter.updateSession(
newSession.session.id,
{
selectedWallet: 'test',
},
)

console.log('session updated')
}
}
}),
},
5 replies
BABetter Auth
Created by ぱいなぷー on 2/28/2025 in #help
How to Retrieve DATABASE_URL in Cloudflare?
I think you should use environment variables, you can add it in workers -> settings
4 replies