forked from bielern/nextjs-patent-cockpit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
31 lines (27 loc) · 896 Bytes
/
middleware.ts
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
29
30
31
import { getIronSession } from "iron-session/edge";
import { NextRequest, NextResponse } from "next/server";
import { ironConfig } from "./lib/config";
export async function middleware(req:NextRequest) {
const res = NextResponse.next()
const session = await getIronSession(req, NextResponse.next(), ironConfig)
const { user } = session
//console.log({user})
if (!user?.isLoggedIn) {
const url = req.nextUrl.clone()
url.pathname = "/login"
return NextResponse.rewrite(url)
}
return res
}
export const config = {
matcher: [
/*
* Matches all request paths except for the ones starting with:
* - /api/auth (AUTH routes)
* - /login & /signup
* - _next/static (static files)
* - favicon.ico (favicon file)
*/
'/((?!api/auth|login|signup|_next/static|favicon).*)',
]
}