Files
remotelink-docker/middleware.ts
2026-04-10 15:36:33 -07:00

26 lines
674 B
TypeScript

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)$).*)',
],
}