Unable to set JWT contents #2565
Answered
by
balazsorban44
tessamerrill
asked this question in
Help
-
I'm trying to add custom data to the JWT with the following code: import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
import { Login } from '../../../util/api/auth'
import { GetUserInformation } from '../../../util/api/user'
export default NextAuth({
providers: [
Providers.Credentials({
name: 'Credentials',
credentials: {
email: { label: "Email", type: "text", placeholder: "[email protected]" },
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
const authResult = await Login(credentials.email, credentials.password)
if (!authResult) {
return null;
}
const authUser = await GetUserInformation(authResult.jwt)
return {
auth: authResult,
user: authUser
}
}
})
],
session: {
jwt: true
},
jwt: {
signingKey: '...}',
verificationOptions: {
algorithms: ['HS512'],
}
},
callbacks: {
async jwt(token, user, account, profile, isNewUser) {
console.log(user, token)
return {
user: user?.user,
auth: user?.auth
}
},
}
}) This should be the correct method, right? However, when i use What do I do? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
balazsorban44
Aug 20, 2021
Replies: 1 comment
-
https://next-auth.js.org/configuration/callbacks Check the jwt and session callbacks. You will have to use an |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tessamerrill
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://next-auth.js.org/configuration/callbacks
Check the jwt and session callbacks.
You will have to use an
if
instead of optional chaining.