-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
37 lines (30 loc) · 1.04 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
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import cookieParser from 'cookie-parser'
// const authenticateToken = (token: string) => {
// const secret = process.env.ACCESS_TOKEN_SECRET;
// if (!secret) {
// throw new Error('ACCESS_TOKEN_SECRET is not defined');
// }
// jwt.verify(token, secret, (err, user) => {
// if (err) return false;
// })
// return true;
// }
// This function can be marked `async` if using `await` inside
export async function middleware(request: NextRequest) {
const authTokens = request.cookies.get('accessToken')
const pathname = new URL(request.url).pathname;
if (pathname === '/') {
if (authTokens) {
return NextResponse.redirect(new URL('/game/poker', request.url))
}
}
// if (pathname.startsWith('/game/poker') && !authTokens) {
// return NextResponse.redirect(new URL('/', request.url));
// }
}
// See "Matching Paths" below to learn more
export const config = {
matcher: ['/','/game/poker']
}