fix random auth errors
idk how i did it
This commit is contained in:
25
src/middleware.ts
Normal file
25
src/middleware.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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)(.*)',
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user