Skip to content

Commit

Permalink
Merge pull request #101 from Qfeed-Dev/staging
Browse files Browse the repository at this point in the history
fix: 회원가입 로직 수정
  • Loading branch information
hamo-o authored Oct 15, 2023
2 parents ef98320 + d7bef2f commit e56c45c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/apis/auth/checkSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export async function checkSignIn(request: NextRequest) {
const { pathname } = request.nextUrl;

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

export async function checkSignUp(request: NextRequest) {
const user = await checkUser(request);
const url = request.nextUrl.clone();
const { pathname } = request.nextUrl;

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

if (user.name && user.schoolType) {
return NextResponse.next();
Expand Down
5 changes: 3 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { checkSignIn } from "./apis/auth/checkSignIn";
import { checkSignUp } from "./apis/auth/checkSignUp";
import { qFeedAxios } from "./apis/axios";

export async function middleware(request: NextRequest) {
Expand All @@ -10,8 +11,8 @@ export async function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
requestHeaders.set("Authorization", `Bearer ${token}`);

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

return NextResponse.next();
Expand Down

0 comments on commit e56c45c

Please sign in to comment.