-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
28 lines (23 loc) · 1 KB
/
Copy pathmiddleware.ts
File metadata and controls
28 lines (23 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// https://authjs.dev/getting-started/session-management/protecting
// Example repo: https://github.com/nextauthjs/next-auth/blob/main/apps/examples/nextjs-pages/middleware.ts
//export { auth as middleware } from "@/auth"
// https://authjs.dev/getting-started/migrating-to-v5#authentication-methods
// use the auth method as a wrapper to implement more logic inside the middleware
// Example: https://github.com/plasmicapp/plasmic-next-auth-example/blob/master/middleware.ts
import { auth } from "@/auth"
export default auth((req) => {
if (!req.auth && req.nextUrl.pathname !== "/profile") {
const newUrl = new URL("/profile", req.nextUrl.origin)
return Response.redirect(newUrl)
}
})
// Only run on these paths
// Read more: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
// Also exclude plasmic-host path from the middleware
export const config = {
matcher: [
"/:path((?!_next/|api/|favicon\\.ico|plasmic-host).*)",
"/certify/(.*)",
"/admin/(.*)"
]
};