fixing mirgration issues
This commit is contained in:
+2
-12
@@ -1,30 +1,20 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
import { betterFetch } from '@better-fetch/fetch'
|
||||
|
||||
const PUBLIC_PATHS = ['/login', '/api/auth']
|
||||
|
||||
type Session = { user: { id: string; email: string } }
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl
|
||||
|
||||
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') ?? '' },
|
||||
})
|
||||
const session = request.cookies.get('better-auth.session_token')
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.redirect(new URL('/login', request.url))
|
||||
}
|
||||
|
||||
if (pathname === '/login') {
|
||||
return NextResponse.redirect(new URL('/dashboard', request.url))
|
||||
}
|
||||
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user