NextAuth Session Not Populated with User Data after Successful Login (Credentials Provider) #9317
Replies: 3 comments 1 reply
-
same problem,please let me know if anyone solves it |
Beta Was this translation helpful? Give feedback.
-
I authorize like this: export const { auth, signIn, signOut } = NextAuth({
...authConfig,
providers: [
credentials({
async authorize(credentials) {
const parsedCredentials = z
.object({ login: z.string(), password: z.string() })
.safeParse(credentials);
if (!parsedCredentials.success) return null;
const { login, password } = parsedCredentials.data;
const user = await fetchUserByLogin(login);
if (!user) return null;
if (!(await compare(password, user.passwordHash))) return null;
return {
id: user._id.toString(),
name: user.login,
email: user.email,
image: user.avatarUrl,
};
},
}),
],
}); And I have similar issue, since I use v5, I use |
Beta Was this translation helpful? Give feedback.
-
for me it only works if i set the strategy to "jwt" otherwise user is undefined after successful login session: {
strategy: "jwt",
} |
Beta Was this translation helpful? Give feedback.
-
I'm using NextAuth with a CredentialsProvider and JWT session in my app. When a user logs in, the authorize callback correctly returns a user object:
However, the session callback and getSession() do not have the user data available:
Here's the full code along with its logs:
Logs:
I have tried:
But none have resolved the issue.
The user data seems to be dropped between the authorize and session callbacks.
Any ideas what could be going wrong here or how I can further debug why the user object is not populating the session?
Things I have verified:
Any help or insights appreciated!
Beta Was this translation helpful? Give feedback.
All reactions