fixing url issues

This commit is contained in:
Rolf
2026-03-18 13:56:42 +01:00
parent 55095f5bce
commit 2d24a7a787
+6 -3
View File
@@ -7,18 +7,21 @@ type Session = { user: { id: string; email: string } }
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
const isPublic = PUBLIC_PATHS.some((p) => pathname.startsWith(p))
if (PUBLIC_PATHS.some((p) => pathname.startsWith(p))) {
return NextResponse.next()
}
const { data: session } = await betterFetch<Session>('/api/auth/get-session', {
baseURL: `http://localhost:${process.env.PORT ?? 3000}`,
headers: { cookie: request.headers.get('cookie') ?? '' },
})
if (!session && !isPublic) {
if (!session) {
return NextResponse.redirect(new URL('/login', request.url))
}
if (session && pathname === '/login') {
if (pathname === '/login') {
return NextResponse.redirect(new URL('/dashboard', request.url))
}