-
Hey, I'm trying to setup a multi step login flow with next-auth. Based on my current understanding I can setup multiple credential providers. This would essentially allow me to have something like this providers: [
Credentials({
id: 'login',
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Login',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
credentials: {},
authorize: nextAuthLogin,
}),
Credentials({
id: 'mfa',
name: 'Mfa',
credentials: {},
authorize: nextAuthMfaConfirm,
}),
], This would me to use both credentials through the jwt jwt: async ({ token, user }): Promise<any> => {
console.log('jwt callback [token] ***', token)
console.log('jwt callback [user] ***', user)
if (user) {
token.user = user
}
console.log('jwt callback [token-after]', token)
// user data is data received after signin
// and or session client access
return Promise.resolve(token)
}, session session: async ({ session, user, token }) => {
console.log('session callback [session] ***', session)
console.log('session callback [user] ***', user)
console.log('session callback [token] ***', token)
// const encodedSessionId = jwt.sign(token, process.env.SECRET, { algorithm: 'HS256' })
// at root keep session data
session.user = token.user
// user object
session.user.email = String(token?.user.username)
console.log('session callback [session-after] ***', token)
return Promise.resolve(session)
}, In my first login credential when passing What I notice in particular is that my JWT callback is called twice, on the first call I see my new set user object, but on the second call it has the previous user data, which I'm assuming is what is then passed to the session callback. Is this expected or am I missing something? I would expect the session callback to now have the Thanks for the feedback and great plugin! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I was able to figure it out. The reason it was not updating was because my data was too large for the JWT cookie. When I reduced the amount of data being passed this worked correctly. |
Beta Was this translation helpful? Give feedback.
I was able to figure it out.
The reason it was not updating was because my data was too large for the JWT cookie. When I reduced the amount of data being passed this worked correctly.