Skip to content

Commit

Permalink
fix: 회원가입 체크를 토큰 확인 안에서 수행
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Oct 15, 2023
1 parent 3a9b18a commit 6625ba0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/apis/auth/checkSignIn.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { checkSignUp } from "./checkSignUp";

export async function checkSignIn(request: NextRequest) {
const token = request.cookies.get("accessToken")?.value;
const url = request.nextUrl.clone();

if (token) {
return NextResponse.next();
if ("/((?!auth).*)") {
return checkSignUp(request);
} else {
return NextResponse.next();
}
} else {
url.pathname = "/account";
return NextResponse.redirect(url);
Expand Down
3 changes: 0 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { checkSignUp } from "./apis/auth/checkSignUp";
import { checkSignIn } from "./apis/auth/checkSignIn";
import { qFeedAxios } from "./apis/axios";

Expand All @@ -12,8 +11,6 @@ export async function middleware(request: NextRequest) {
requestHeaders.set("Authorization", `Bearer ${token}`);

if (pathname.match("/((?!account).*)")) {
return await checkSignUp(request);
} else if (pathname.match("/((?!account|auth).*)")) {
return await checkSignIn(request);
}

Expand Down

0 comments on commit 6625ba0

Please sign in to comment.