-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
33 lines (30 loc) · 997 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
32
33
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
const SESSION_ID_COOKIE_NAME = 'SESSION_ID';
// This function can be marked `async` if using `await` inside
export async function middleware(request: NextRequest) {
const response = NextResponse.next();
if (request.cookies.has(SESSION_ID_COOKIE_NAME)) {
const mySpecialCookies = request.cookies.get(SESSION_ID_COOKIE_NAME);
if (mySpecialCookies) {
const sessionId = mySpecialCookies.value;
}
} else {
console.log('session cookie not found');
}
console.log('hello middleware');
return response;
}
// See "Matching Paths" below to learn more
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)'
]
};