26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
import { auth } from "@/auth"
|
|
|
|
export default auth((req) => {
|
|
const { nextUrl } = req
|
|
const isLoggedIn = !!req.auth
|
|
|
|
// Protect dashboard routes
|
|
// if (nextUrl.pathname.startsWith('/api') && !isLoggedIn) {
|
|
// return Response.redirect(new URL('/signin', nextUrl))
|
|
// }
|
|
|
|
// Redirect logged-in users from sign-in page
|
|
if (nextUrl.pathname.startsWith('/signin') && isLoggedIn) {
|
|
return Response.redirect(new URL('/', nextUrl))
|
|
}
|
|
})
|
|
|
|
export const config = {
|
|
matcher: [
|
|
// Skip Next.js internals and all static files
|
|
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
|
|
// Always run for API routes
|
|
'/(api|trpc)(.*)',
|
|
],
|
|
}
|