Auth not working properly in Nextjs
hey guys what could be the reason that convex auth is not working properly on my nextjs app?
setup everything as on the tutorial but after login, i dont get redirected and even if i manually go to protected route, i still get redirected back to /login page, and isAuthenticated is always loggin false
9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
added this console.log
console.log('server identity', await ctx.auth.getUserIdentity())
and right after signin its loggin the identity, but as soon as i refresh the page it logs null again!
this should be the reason!
what am i doing wrong?I believe you need to use
isAuthenticatedNextJs
for checking auth status in nextjs middleware
You can add it to the imports from @convex-dev/auth/nextjs/server
just changed to
isAuthenticatedNextJs
and its still returning false
is there any github repo with working convex auth on nextjs?
providers are both set according to nextjs guide on the convex site
but im not doing any server action and triggering signIn
on the page with use client
Here's a template that implements next and convex auth: https://github.com/get-convex/template-nextjs-convexauth-shadcn
GitHub
GitHub - get-convex/template-nextjs-convexauth-shadcn: Convex + Nex...
Convex + Next.js + Convex Auth. Contribute to get-convex/template-nextjs-convexauth-shadcn development by creating an account on GitHub.
oh interesting that doesn't use isAuthenticatedNextJs
Yeah the way you were doing it before is how the template works
What version of convex auth are you on
i dont what i changed specifically lol, but now it works! thanks @erquhart
lol glad it's working
okay for anyone who encounters this same error, make sure to import convex providers from '@convex-dev/auth/nextjs' package, i mistakenly was importing it from
react
package!