fixing url issues
This commit is contained in:
+6
-3
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user