-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
28 lines (22 loc) · 790 Bytes
/
proxy.ts
File metadata and controls
28 lines (22 loc) · 790 Bytes
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
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";
import checkProfileToken from "./lib/helper/checkProfileToken";
export const proxy = async (req: NextRequest) => {
const cookieStore = await cookies();
const cookie = cookieStore.get("profile-token");
if(!cookie) {
return NextResponse.redirect(new URL("/profile-setup", req.url));
}
const token = cookie?.value;
if(!token) {
return NextResponse.redirect(new URL("/profile-setup", req.url));
}
const decoded = checkProfileToken(token);
if(decoded === null) {
return NextResponse.redirect(new URL("/profile-setup", req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/problems, /profile"],
}