Next.js Discord

Discord Forum

How to get access_token on login in database stratejy?

Unanswered
yekoba posted this in #help-forum
Open in Discord
i want to get access_token on login, this is my code,

export const { auth, handlers, signIn, signOut } = NextAuth({
providers: [Google],
adapter: PrismaAdapter(prisma),

callbacks: {
session: async ({ session, user }) => {
session.user = user;

return session;
},
},
});

but since i am using database stratejy, jwt callback doesnt work, access token is stored in database so how to call it in login and attach it to session obj?

1 Reply

callbacks: {
session: async ({ session, user }) => {
session.user = user;
var newUs = await prisma.account.findFirst({
where: {
userId: user.id,
},
});
session.access_token = newUs?.access_token;
return session;
},
},
i updated my method like this
it works for now but is it good approach?