Skip to content

Commit

Permalink
fix: url constants로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed Aug 31, 2024
1 parent 44b15c0 commit 9ae85c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 4 additions & 0 deletions apps/admin/constants/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const clientUrl =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? process.env.NEXT_PUBLIC_CLIENT_PROD_URL
: process.env.NEXT_PUBLIC_CLIENT_DEV_URL;
10 changes: 3 additions & 7 deletions apps/admin/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { dashboardApi } from "apis/auth/dashboardApi";
import { cookieKey } from "constants/cookieKey";
import { clientUrl } from "constants/url";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
import setExpireTime from "utils/setExpireTime";

export const config = {
matcher: ["/studies/:path*", "/participants/:path*"],
};

const middleware = async () => {
const url =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production"
? process.env.NEXT_PUBLIC_CLIENT_PROD_URL
: process.env.NEXT_PUBLIC_CLIENT_DEV_URL;
const cookieStore = cookies();
const accessToken = cookieStore.get(cookieKey.accessToken)?.value;
const cacheCookie = cookieStore.get(cookieKey["middleware-executed"])?.value;

if (!accessToken) {
return NextResponse.redirect(new URL("/auth", url));
return NextResponse.redirect(new URL("/auth", clientUrl));
}

if (!cacheCookie) {
try {
const { manageRole, studyRole } = await dashboardApi.getDashboardInfo();
if (studyRole === "STUDENT" && manageRole === "NONE") {
return NextResponse.redirect(new URL("/auth", url));
return NextResponse.redirect(new URL("/auth", clientUrl));
}
const response = NextResponse.next();
response.cookies.set(cookieKey["middleware-executed"], "true", {
Expand Down

0 comments on commit 9ae85c5

Please sign in to comment.