-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
39 lines (34 loc) · 1.12 KB
/
proxy.ts
File metadata and controls
39 lines (34 loc) · 1.12 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
29
30
31
32
33
34
35
36
37
38
39
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function proxy(request: NextRequest) {
const token = request.cookies.get('auth-token')?.value
if (!token) {
if (request.nextUrl.pathname.startsWith('/home') ||
request.nextUrl.pathname.startsWith('/admin') ||
request.nextUrl.pathname.startsWith('/teams') ||
request.nextUrl.pathname.startsWith('/tasks') ||
request.nextUrl.pathname.startsWith('/my-tasks')) {
return NextResponse.redirect(new URL('/login', request.url))
}
}
// Redirect authenticated users from login/register to home
if (token) {
if (request.nextUrl.pathname === '/login' ||
request.nextUrl.pathname === '/register') {
return NextResponse.redirect(new URL('/home', request.url))
}
}
return NextResponse.next()
}
export const config = {
matcher: [
'/',
'/login',
'/register',
'/home/:path*',
'/admin/:path*',
'/teams/:path*',
'/tasks/:path*',
'/my-tasks/:path*'
],
}