-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
39 lines (28 loc) · 1.16 KB
/
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
34
35
36
37
38
39
import { NextResponse } from 'next/server';
import { NextRequest } from 'next/server';
import { AUTH_TOKEN_KEY } from './app/constants';
export async function middleware(req: NextRequest) {
const userToken = req.cookies.get(AUTH_TOKEN_KEY as string)?.value;
// const sessionToken = req.cookies.has(ClientSession as string);
// const data = jwt.verify(userToken as string, JWT_TOKEN as string)
// console.log("data", data);
// console.log('USER TOKEN', userToken);
// console.log('ISSESSION', userToken);
const host = req.nextUrl.protocol + req.headers.get('host');
// console.log("host", host);
// user login control
if (userToken && req.nextUrl.pathname === '/signin') {
return NextResponse.redirect(new URL(`${host}/`));
}
if (userToken && req.nextUrl.pathname === '/signup') {
return NextResponse.redirect(new URL(`${host}/`));
}
// Add a closing bracket here
// if (!userToken && req.nextUrl.pathname.includes('')) {
// return NextResponse.redirect(new URL(`${host}/signin`));
// }
// Add a closing bracket here
}
export const config = {
matcher: ['/:path*','/signin/:path*', '/signup/:path*'], // Add "/profile" path here
};