vercel / platforms

A full-stack Next.js app with multi-tenancy and custom domain support. Built with Next.js App Router and the Vercel Domains API.
https://app.vercel.pub
5.73k stars 767 forks source link

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

Open strzeluk opened 9 months ago

strzeluk commented 9 months ago

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 commented 8 months ago

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