nextjs middleware
Currently trying to upgrade to next 15. However, when following the changelog, the middleware seem to be broken. I have updated the middleware to be identical to the example shown at https://labs.convex.dev/auth/authz/nextjs. It seems like convexAuth.isAuthenticated() always returns false and therefore continuously redirecting back to the signin page.
Server-side authentication in Next.js - Convex Auth
Authentication library for your Convex backend
10 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!
Welcome! Just checking -
isAuthenticated
returns a promise, are you await-ing it?
I guess if you're getting false you'd have to be
ah nvm the example you linked includes awaiting the resultYeah, I am awaiting in both cases.
What does your convex/auth.ts look like?
And what do your server logs look like?
@Gnomis we were missing a step in the changelog, I've just added it here:
https://github.com/get-convex/convex-auth/blob/main/CHANGELOG.md#0076
I don't know that this is your issue without knowing answers to the previous two questions but it's a good guess.
Perfect! That fixed the issue. For the record, auth.ts looked like this. Simply adding the export of isAuthenticated fixed the issue.
Great, sorry for the missing instructions here!
Might try to make this fail more loudly, maybe
isAuthenticated
in middleware could fail with a more helpful error message
Ah there wasn't any error message! Ok we can fix that https://github.com/get-convex/convex-auth/blob/e6cbdc64c6000f295b693b044df746e3d42c1f71/src/nextjs/server/index.tsx#L302-L313perfect, once we expose the error is looks like this
Awesome! Makes it way easier to debug the error 🙂
I'll make it a little custom, we could do better for
auth:isAuthenticated
specifically by mentioning this was a change in the libraryPR up, going to chat with other folks working on auth about it https://github.com/get-convex/convex-auth/pull/144
GitHub
Make isAuthenticated in middleware fail more loudly. by thomasballi...
Make the Next.js middleware function isAuthenticated fail more loudly. Previously it returned false in the case of a Convex backend that didn't expose an endpoint called auth:isAuthenticate...