Initial commit
This commit is contained in:
25
middleware.ts
Normal file
25
middleware.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { auth } from '@/auth'
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export default auth((req) => {
|
||||
const { nextUrl, auth: session } = req
|
||||
const isLoggedIn = !!session
|
||||
|
||||
const isProtectedPath =
|
||||
nextUrl.pathname.startsWith('/dashboard') ||
|
||||
nextUrl.pathname.startsWith('/viewer')
|
||||
|
||||
if (isProtectedPath && !isLoggedIn) {
|
||||
const loginUrl = new URL('/auth/login', nextUrl.origin)
|
||||
loginUrl.searchParams.set('callbackUrl', nextUrl.pathname)
|
||||
return NextResponse.redirect(loginUrl)
|
||||
}
|
||||
|
||||
return NextResponse.next()
|
||||
})
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user