-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
24 lines (21 loc) · 846 Bytes
/
middleware.ts
File metadata and controls
24 lines (21 loc) · 846 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
import { getSession } from "@/common/utils/session/get-session";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const shouldLoginPath = ["/record", "/mypage", "/curation"];
const shouldNotLoginPath = ["/login"];
export async function middleware(request: NextRequest) {
const auth_info = await getSession();
if (
!auth_info?.data?.accessToken &&
shouldLoginPath.some((path) => request.url.includes(path.split("/")[1]))
) {
return NextResponse.redirect(new URL("/login", request.url));
} else if (
auth_info?.data?.accessToken &&
shouldNotLoginPath.some((path) => request.url.includes(path.split("/")[1]))
)
return NextResponse.redirect(new URL("/", request.url));
}
export const config = {
matcher: ["/record/:path*", "/mypage", "/curation", "/login/:path*"],
};