Gnomis
Gnomis•4d ago

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
Convex Bot
Convex Bot•4d ago
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!
erquhart
erquhart•4d ago
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 result
Gnomis
GnomisOP•4d ago
Yeah, I am awaiting in both cases.
No description
ballingt
ballingt•4d ago
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.
Gnomis
GnomisOP•4d ago
Perfect! That fixed the issue. For the record, auth.ts looked like this. Simply adding the export of isAuthenticated fixed the issue.
No description
ballingt
ballingt•4d ago
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-L313
ballingt
ballingt•4d ago
perfect, once we expose the error is looks like this
No description
Gnomis
GnomisOP•4d ago
Awesome! Makes it way easier to debug the error 🙂
ballingt
ballingt•4d ago
I'll make it a little custom, we could do better for auth:isAuthenticated specifically by mentioning this was a change in the library
ballingt
ballingt•4d ago
PR 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&#39;t expose an endpoint called auth:isAuthenticate...