-
Notifications
You must be signed in to change notification settings - Fork 5
/
middleware.ts
44 lines (41 loc) · 1.28 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
40
41
42
43
44
import { checkSignedIn } from "./utils/checkSignedIn";
import { globalJWT } from "./middlewares/globalJWT";
import { userJWT } from "./middlewares/userJWT";
import { NextRequest, NextResponse } from "next/server";
export async function middleware(request: NextRequest) {
const pathname = String(request.nextUrl.pathname);
if (
(pathname.includes("/logIn") || pathname.includes("/reset-password")) &&
(await checkSignedIn(request))
) {
return NextResponse.redirect(new URL("/projects", request.url));
}
if (
(pathname === "/settings" ||
pathname.includes("/projects") ||
pathname.includes("/tasks")) &&
(await checkSignedIn(request)) === false
) {
return NextResponse.redirect(new URL("/logIn", request.url));
}
if (pathname.includes("/api/user") || pathname === "/api/settingsChange") {
return userJWT(request);
}
if (
pathname.includes("/api/sendEmail") ||
pathname.includes("/api/reset-password")
) {
return globalJWT(request);
}
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
"/((?!_next/static|_next/image|favicon.ico).*)",
],
};