Skip to content

Commit

Permalink
Merge pull request #114 from JNU-econovation/feat/8-switch-cookie
Browse files Browse the repository at this point in the history
리다이렉트문 수정
  • Loading branch information
geongyu09 authored Mar 3, 2024
2 parents bf264af + 93bb5b6 commit d7d91a0
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 61 deletions.
6 changes: 0 additions & 6 deletions frontend/app/(WithNavbar)/admin/page.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/app/(WithNavbar)/applicant/page.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/app/(WithNavbar)/interview/page.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/app/(WithNavbar)/kanban/page.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/app/(WithNavbar)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import CommonNavbar from "@/components/common/navbar/Navbar";
import Validate from "@/components/user/Validate.component";
import { PropsWithChildren } from "react";
import { headers } from "next/headers";

Expand All @@ -13,7 +12,6 @@ const ApplicantPage = ({ children }: WithNavbarLayout) => {

return (
<div className="px-24 min-w-[1280px] flex p-12">
<Validate />
<CommonNavbar
generation={generation}
currentPath={currentPath}
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/kanban/[generation]/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import KanbanColumnDetailCard from "@/components/kanban/column/ColumnWithBackButton.component";
import KanbanDetailApplicant from "@/components/kanban/content/DetailApplicant.component";
import Validate from "@/components/user/Validate.component";
import { KanbanCardReq } from "@/src/apis/kanban";
import KanbanDetailWork from "@/components/kanban/content/DetailWork.component";

Expand Down Expand Up @@ -52,7 +51,6 @@ const KanbanBoardDetailPage = ({
}: KanbanBoardDetailPageProps) => {
return (
<main className="flex mt-8 overflow-auto pt-12 pl-12">
<Validate />
<KanbanColumnDetailCard
columnIndex={+columnIndex ?? 0}
generation={generation}
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Txt from "@/components/common/Txt.component";
import HomeCardComponent from "@/components/main/Card.component";
import Validate from "@/components/user/Validate.component";
import { MAIN_MENU, CURRENT_GENERATION } from "@/src/constants";

const HomePage = () => {
Expand All @@ -13,7 +12,6 @@ const HomePage = () => {

return (
<main className="flex justify-between">
<Validate />
<div className="pt-24 pl-16 flex flex-col gap-2">
<Txt typography="head" className="font-semibold uppercase">
econovation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const canNext = (applicationNames: Array<string>) => {
}
return (
!(localStorageValueFromName.length === 0) ||
(name === "channel" && localStorage.get("channelEtc", EMPTY_STRING).length !== 0)
(name === "channel" &&
localStorage.get("channelEtc", EMPTY_STRING).length !== 0)
);
});
};
Expand Down
23 changes: 0 additions & 23 deletions frontend/components/user/Validate.component.tsx

This file was deleted.

14 changes: 12 additions & 2 deletions frontend/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import { CURRENT_GENERATION, needValidatePath } from "./src/constants";

export function middleware(request: Request) {
export function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-url", request.url);

const redirectUrl = (url: string) => {
return NextResponse.redirect(new URL(url, request.url));
};

const isRedirectPath = needValidatePath.includes(request.nextUrl.pathname);

if (isRedirectPath)
return redirectUrl(`${request.nextUrl.pathname}/${CURRENT_GENERATION}`);

return NextResponse.next({
request: {
headers: requestHeaders,
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/apis/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { https } from "@/src/functions/axios";
import { localStorage } from "@/src/functions/localstorage";

interface SignInReq {
email: string;
Expand All @@ -18,8 +17,6 @@ export const signIn = async ({ email, password }: SignInReq) => {
alert("로그인이 성공하였습니다");
}

localStorage.set("accessToken", data.accessToken);
localStorage.set("refreshToken", data.refreshToken);
return true;
} catch (error) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,10 @@ export const ORDER_MENU = {
{ type: "score", string: "점수순" },
],
} as const;

export const needValidatePath = [
"/admin",
"/applicant",
"/interview",
"/kanban",
];
4 changes: 2 additions & 2 deletions frontend/src/functions/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const https = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
});

https.defaults.withCredentials = true;

https.interceptors.request.use((config) => {
const token = JSON.parse(localStorage.getItem("accessToken") ?? '""');
if (token) {
Expand All @@ -20,8 +22,6 @@ https.interceptors.response.use(
},
(error) => {
if (error.response.status === 401 || error.response.status === 403) {
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");
alert("로그인이 필요합니다.");
window.location.href = "/signin";
}
Expand Down

0 comments on commit d7d91a0

Please sign in to comment.