initial webapp

This commit is contained in:
2025-07-15 18:58:21 +02:00
parent 835b73552b
commit 253111f741
32 changed files with 3885 additions and 77 deletions

24
middleware.ts Normal file
View File

@@ -0,0 +1,24 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const token = request.cookies.get('habit-tracker-token');
const isAuthPage = request.nextUrl.pathname === '/welcome';
const isDashboard = request.nextUrl.pathname === '/dashboard';
// If trying to access dashboard without token, redirect to welcome
if (isDashboard && !token) {
return NextResponse.redirect(new URL('/welcome', request.url));
}
// If trying to access welcome page with token, redirect to dashboard
if (isAuthPage && token) {
return NextResponse.redirect(new URL('/dashboard', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/dashboard', '/welcome'],
};