bugfix: authenticated users seen a blank page instead of their dashboard when reopen the site

This commit is contained in:
2026-04-28 11:57:29 +03:30
parent 26bd35ae3c
commit c12509ad31
2 changed files with 31 additions and 10 deletions

View File

@@ -10,6 +10,11 @@ export function middleware(request: NextRequest) {
const token = request.cookies.get('accessToken')?.value;
const isAuthenticated = !!token;
// If a logged-in user opens home, send them to dashboard.
if (isAuthenticated && pathname === '/') {
return NextResponse.redirect(new URL('/today', request.url));
}
// Always allow public routes first
if (publicRoutes.includes(pathname)) {
// If user is already logged in and tries to access login/register → redirect to dashboard