Next.js 15 (Canary) - Issue with Convex Auth Context
I'm using Next.js 15 (canary version), and everything works fine most of the time. However, occasionally after a hard reload, the middleware indicates the user is authenticated, but mutations fail because the ctx.user is undefined. For example, inside a mutation:
...
const userId = await getAuthUserId(ctx)
...
returns undefined, This issue seems to resolve itself after a few refreshes.
What could be causing this behavior?
I'm using:
"@auth/core": "^0.37.4",
"@convex-dev/auth": "^0.0.75",
"convex": "^1.17.3",
"convex-helpers": "^0.1.65",
8 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!
Digging a bit deeper, it seems that on the page:
export const dynamic = 'force-static';
is what triggers the issue.
@Julián David Could you open an issue on https://github.com/get-convex/convex-auth, if you're feeling generous with a small reproduction?
This sounds expected from https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
since that means no cookies, there's no way you could remain logged in
but if we're going to get questions / GitHub issues about it we should mention it in a Next.js guide or docs
the good news is all this https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic is being deprecated eventually in favor of https://nextjs.org/docs/canary/app/api-reference/config/next-config-js/dynamicIO which should be simpler to explain
Can I ask @Julián David why you used
export const dynamic = 'force-static'
, is there a tutorial you were following or a guide that recommended it?I want to generate a static page while streaming server components. I'm also testing PPR. 🙂
Do you want to use auth on that static page?
What does this mean, the outer layout is static but the server components aren't?
If you could write up what you were trying to do or show a code sample in a Convex Auth GitHub issue that would be helpful
I'll definitely get to it this weekend. Thank you for your prompt response!
Yeah, it doesn't make sense now that I'm thinking about it properly hahaha
it will help for us to clearly document this somewhere, so even if it's not something you still want to do feel free to write up an issue