Token is null when using credentials provider #4325
-
When I call getToken in a Also the jwt token doesn't look right. authorize returns an object also containing email and role, but those don't seem to appear when printing the token in the I'm 99% sure it's a configuration issue, but I can't find it
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
export default NextAuth({
providers: [
CredentialsProvider({
id: 'credentials',
name: 'Email',
credentials: {
mail: { label: "Email", type: "text" },
password: { label: "Password", type: "password" }
},
async authorize(credentials, req) {
console.log("authorizing")
const res = await fetch(process.env.SITE_URL + "/api/user/login", {
method: 'POST',
body: JSON.stringify(credentials),
headers: { "Content-Type": "application/json" }
})
const userResponse = await res.json()
if (res.status === 200) {
const user = await JSON.parse(userResponse.user)
return user
}
return null
}
}),
],
callbacks: {
async jwt({ token, account }) {
console.log("jwt:")
console.log(token)
// prints:
// jwt:
// {
// name: 'Petru Trimbitas',
// iat: 1649090585,
// exp: 1651682585,
// jti: 'b9427004-b5f7-4743-b85c-9d0ab4a73198'
// }
return token
}
},
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "jwt",
maxAge: 30 * 24 * 60 * 60,
},
jwt: {
secret: process.env.JWT_SECRET,
},
}) |
Beta Was this translation helpful? Give feedback.
Answered by
rizchaerul
Apr 5, 2022
Replies: 1 comment 2 replies
-
The role and email are in user, not in token, here's my code
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
S7012MY
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The role and email are in user, not in token, here's my code