Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors are not showing on login page because of redirects in middleware #388

Open
strzeluk opened this issue Feb 16, 2024 · 1 comment
Open

Comments

@strzeluk
Copy link

This example is so buggy...

I don't know if someone notice but toasts with errors will never show on login page because of permanent redirection in middleware, for example:

localhost:3000/login?error=something will be redirected to localhost:3000/login

Errors from login are displayed based on error in url searchParams. So you have to change some code in middleware.ts file:

   const pathWithoutQuery = path.split("?")[0];
   if (!session && pathWithoutQuery !== "/login") {
     return NextResponse.redirect(new URL(`/login`, req.url));
   } else if (session && pathWithoutQuery == "/login") {
     return NextResponse.redirect(new URL("/", req.url));
   }
   return NextResponse.rewrite(
     new URL(`/app${path === "/" ? "" : path}`, req.url)
   );
@HeyReihan
Copy link

Screenshot_20240328-084139
I changed it to look like this. So we have to manually go to url /

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants