Unable to authenticate Convex with next auth when provider is Credentials.
I have followed this post to setup the adapter https://stack.convex.dev/nextauth-adapter, and authenticate Convex with next auth, and it works with providers with github and google, but it does not with credentials.
I am able to authenticate in the client side still with credentials, but unable to authenticate the same with Convex. It is not returning any sessions with credentials provider.
Here is my auth.ts
I feel like I need to access the token callback to pass theJWT.
Have I missed something in the docs?
15 Replies
What do your providers look like?
Here you go.
Doesn't look like this ever creates a user given credentials?
I would move the password hashing and checking logic to Convex, here's an example: https://github.com/xixixao/convex-auth/blob/main/convex/auth.ts
GitHub
convex-auth/convex/auth.ts at main · xixixao/convex-auth
Demonstration of authentication purely via Convex. Contribute to xixixao/convex-auth development by creating an account on GitHub.
It does, i guess.
getUserByEmail
is actually a wrapper of the query being fetched.
I have a register form which calls the register action on submit.
Each function is actually a wrapper of the query or mutation being called from convex.
My applicaiton registers the user just like it should, and I can see the data in the convex database, and I am able to login with the same too without any issues.
I just am not able to authenticate it with Convex, so that I can authenticate my Convex functions.Does the logic in
signIn
callback work?
What does the console.log(session);
line print?The signIn callback, logs the user and account
But the sessions callback logs null.
But it works when I set the session strategy as jwt, and in the jwt callback return the token. I feel like there is something I am misunderstanding here.
Have you tried add
debug: true
to NextAuth and see if it prints anything useful?This is what I get after adding debug as true
Hmm, I'm honestly not sure. I'd have to try credentials and see if it works. You could ask on the Auth.js discord/github too.
Will be doing that. Thanks for the time tho.
Hey @Michal Srb ,
This is the thread I came across https://github.com/nextauthjs/next-auth/issues/3970
So apparently the credentials provider does not fire the session callback.
GitHub
Credentials Provider Not Firing Session Callback · Issue #3970 · n...
Description 🐜 Hello, I'm having trouble with using Credentials Provider where it's not firing the session callback. I've logged the whole process from signin and output with logger func...
Ugh that's uber frustrating
You can use the JWT strategy with Convex if you need to though.
How should I implement that to my existing code? Can you help me with it.
You shouldn't need many changes. You just won't get sessions stored in the Convex DB. Here's a branch of the example repo that uses the JWT strategy:
https://github.com/get-convex/convex-nextauth-template/blob/github-no-db/auth.ts
GitHub
convex-nextauth-template/auth.ts at github-no-db · get-convex/conve...
Example of using Auth.js (NextAuth) with Convex. Contribute to get-convex/convex-nextauth-template development by creating an account on GitHub.