Next.js URL not changing using the documented middleware and ConvexAuth setup
When signing in using password auth, the page changes as expected, but the URL remains the same.
Using the documented Convex Auth password setup, when I go to /sign-in and actually sign-in, the tasks page loads, but the URL remains as
/sign-in
until I refresh.
Not sure if this is a bug or user error and I've missed something.
Root layout:
Middleware:
17 Replies
We don't refresh the page automatically, so the middleware doesn't run and doesn't redirect the user. You need to perform the redirect on the client:
What handles the route switching from /sign-in to /tasks if there's nothing being handled automatically? 😅
My sign-in is literally just
signIn("password", formData);
For OAuth, it's the
redirectTo
param.
For magic links, the user clicks on a link to the destination (also controlled via redirectTo
). For Passwords, there's no redirect. This means the app can stay on the same page and handle the auth changing clientside.
would likely also work for you.But what I'm saying is the page does switch from sign-in to tasks once I sign up 🤔
Ah! I misread the post.
Unless I'm misunderstanding you. I understand we have the refresh after sign-in option, but the page does current switch
All good, common case of written communication shenanigans 😄
We do refresh the server data
Via a server action
Ah, so that's why the page changes from sign-in to tasks
You can see it fire off in the network tab
And why the middleware causes the redirect
Or what I assume is the middleware causing it
Yeah. It's confusing that Next.js keeps the current URL.
Little bit annoying. I wonder if using another form of redirect other than the
nextjsMiddlewareRedirect
wrapper would resolve itI don't think that's the problem. I think it's more what our client does and how Next.js behaves.
I filed https://github.com/get-convex/convex-auth/issues/58
Can you try the snippets above and see if the behavior is ok?
GitHub
Next.js: Passwords refetch server data but Next.js keeps the curren...
See https://discord.com/channels/1019350475847499849/1275574839218016337 This is not great. We could try using router.refresh instead of calling a server action, but I had trouble getting it to wor...
On it 👍
router.push
works but router.refresh
doesn't 🙂
Updated the issueThanks
No prob, happy to help. Just thought I'd spend some time this evening playing around with Convex, it's pretty nice, and I imagine kinks like this will be ironed out with time. Keep up the great work 😄
.