redirection url does not change until I reload
Answered
Spotted Rail posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
I have implemented login and logout for my app using next-auth and middleware, but when the user successfully logs into the dashboard, the URL remains "/signin" instead of "/dashboard" until I reload the page. Similarly when I log out from the app the url shows "/dashboard" instead of "/signin".
Answered by Spotted Rail
Okay so I just downgraded to next14.0.2 from 14.2.3 and the redirection is working fine
Edit: 14.1.0 also works
Edit: 14.1.0 also works
16 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
![Avatar](https://cdn.discordapp.com/embed/avatars/1.png)
Transvaal lion
do you have a window.location.replace anywhere after sign in? i didn't see one
or some sort of routing after login?
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
nope, i dont think it is needed
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
here's my login form:
"use client"
import { useFormState, useFormStatus } from 'react-dom';
import { authenticate } from '@/app/lib/actions';
import { useForm } from "react-hook-form";
export default function SignInForm() {
const { register, handleSubmit, formState: { errors } } = useForm();
const [errorMessage, dispatch] = useFormState(authenticate, undefined);
const action = handleSubmit(async (data) => {
const response = await dispatch(data);
console.log("UserData", data);
});
return (
<form action={action}>
<h2>Sign In</h2>
<input {...register("email", { required: true })} type="email" placeholder="Email" />
{errors.email && <span className="error">Email is required</span>}
<input {...register("password", { required: true })} type="password" placeholder="Password" />
{errors.password && <span className="error">Password is required</span>}
<button type="submit">Sign In</button>
<button onClick={() => signIn("discord")}>Login with Discord</button>
<div
className="flex h-8 items-end space-x-1"
aria-live="polite"
aria-atomic="true"
>
{errorMessage && (
<>
<p className="text-sm text-red-500">{errorMessage}</p>
</>
)}
</div>
</form>
)
}
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
Okay so I just downgraded to next14.0.2 from 14.2.3 and the redirection is working fine
Edit: 14.1.0 also works
Edit: 14.1.0 also works
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
So my next question would be why it doesnt work in latest version of nextjs ?
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
probably it's this bug https://github.com/vercel/next.js/issues/61874
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
how can this issue be solved? there's not much info on this page
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
for now you can try adding the hostname as well
so instead of
you do
for example.
Or just downgrade, which is the simplest solution and what i would do, while waiting for the team to patch this. (Or try to patch it yourself)
so instead of
NextResponse.redirect(new URL("/foo", req.url))
you do
const urlHost = process.env.NODE_ENV === "development"
? "http://localhost:3000"
: "https://yourdomain.com";
NextResponse.redirect(`${urlHost}/foo`);
for example.
Or just downgrade, which is the simplest solution and what i would do, while waiting for the team to patch this. (Or try to patch it yourself)
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
yeah, thanks i'll try this OR maybe not use middleware at all?
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
yeah. plenty of options
if it's a framework bug, we have to use workaround, in this case there are plenty of them
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Spotted RailOP
right