Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 회원가입 로직 수정 #98

Merged
merged 8 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/hooks/account/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useAuth = () => {
return Promise.reject(error);
}
);
router.push("/auth/default");
router.push("/");
},
onError: (error: any) => {
alert(error);
Expand All @@ -45,7 +45,7 @@ export const useAuth = () => {
return Promise.reject(error);
}
);
router.push("/auth/default");
router.push("/");
},
onError: (error: any) => {
alert(error);
Expand Down
6 changes: 1 addition & 5 deletions src/hooks/questions/useQsetMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const useQsetMutation = () => {
onSuccess: () => {
queryClient.invalidateQueries(QSetCursorKeys.all);
},
onError: (error: any) => {
if (error === "AxiosError: Request failed with status code 404") {
return 0;
}
}
onError: (error: any) => {}
});
};

Expand Down
5 changes: 1 addition & 4 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 @@ -11,10 +10,8 @@ export async function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
requestHeaders.set("Authorization", `Bearer ${token}`);

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

return NextResponse.next();
Expand Down
87 changes: 44 additions & 43 deletions src/pages-edit/home/components/MakeOfficial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,54 @@ const MakeOfficial = (props: QuestionProps) => {
const QSet = useQsetCursorQuery();
const newQSet = useQsetMutation();

console.log(QSet);

const [endTime, setEndTime] = useState<number | typeof NaN>(NaN);
const [time, setTime] = useState<Time | undefined>(undefined);

const createNewEndTime = async () => {
const qSetCount = QSet.questionCursor?.length;
const today = new Date();
const nine = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate(),
21
);
const tomorrow = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate(),
24
);

// 아예 초기진입
if (!qSetCount) {
newQSet.mutate();
setEndTime(NaN);
}
// 첫번째 질문 set 끝나고 두번째 질문 set 받기
else if (
qSetCount === 1 &&
QSet.questionCursor &&
QSet.questionCursor[0].isDone
) {
if (+tomorrow - today.getTime() > 3 * 60 * 60 * 1000) {
setEndTime(Date.parse(QSet.questionCursor[0].endAt));
} else {
if (!QSet.isLoading) {
const qSetCount = QSet.questionCursor?.length;

const today = new Date();
const nine = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate(),
21
);
const tomorrow = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate(),
24
);

// 아예 초기진입
if (!qSetCount) {
newQSet.mutate();
setEndTime(NaN);
}
// 첫번째 질문 set 끝나고 두번째 질문 set 받기
else if (
qSetCount === 1 &&
QSet.questionCursor &&
QSet.questionCursor[0].isDone
) {
if (+tomorrow - today.getTime() > 3 * 60 * 60 * 1000) {
setEndTime(Date.parse(QSet.questionCursor[0].endAt));
} else {
setEndTime(+nine);
}
}
// 두번째 질문 set 까지 끝남
else if (
qSetCount === 2 &&
QSet.questionCursor &&
QSet.questionCursor[0].isDone
) {
setEndTime(+nine);
}
// 질문 대답하는 중
}
// 두번째 질문 set 까지 끝남
else if (
qSetCount === 2 &&
QSet.questionCursor &&
QSet.questionCursor[0].isDone
) {
setEndTime(+nine);
}
// 질문 대답하는 중
};

const getTime = () => {
Expand Down Expand Up @@ -102,9 +103,9 @@ const MakeOfficial = (props: QuestionProps) => {
const interval = setInterval(getTime, 1000);
return () => clearInterval(interval);
} else {
if (!QSet.isLoading) createNewEndTime();
createNewEndTime();
}
}, [endTime, QSet]);
}, [endTime, QSet.questionCursor]);

return QSet.isLoading ? (
<Loading />
Expand All @@ -113,7 +114,7 @@ const MakeOfficial = (props: QuestionProps) => {
onClick={props.onClick}
color={colors.primary_qgreen}
>
{QSet.questionCursor?.length && (
{QSet && QSet.questionCursor?.length && (
<BasicQuestionInner>
{QSet.questionCursor[0].isDone ? (
<>
Expand Down
3 changes: 2 additions & 1 deletion src/pages-edit/mypage/components/InfoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function InfoList({
onClick={() => {
if (user.isBlocking) {
unblock.mutate(user.id);
setFollow(false);
} else {
if (follow) {
delFriendMutation.mutate();
Expand All @@ -66,7 +67,7 @@ export default function InfoList({
setFollow((follow) => !follow);
}
}}
state={follow ? "disabled" : "active"}
state={follow && !user.isBlocking ? "disabled" : "active"}
/>
)}
<Flex justify="space-between">
Expand Down
7 changes: 2 additions & 5 deletions src/pages-edit/sign-up/complete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import styled from "styled-components";
import { useRouter } from "next/navigation";
import ButtonFillLarge from "src/components/buttons/button-fill-large";
import NavigationTop from "src/components/navigations/NavigationTopBack";
import NavigationTopBack from "src/components/navigations/NavigationTopBack";

import Text from "src/components/common/Text";
import Flex from "src/components/common/Flex";
Expand All @@ -18,10 +18,7 @@ const Complete = () => {
<Loading />
) : (
<Flex height="100%" direction="column">
<NavigationTop
leftIcon={<Icon icon="LeftArrow" onClick={router.back} />}
title="회원 가입"
/>
<NavigationTopBack title="회원 가입" />
<Flex
height="100%"
direction="column"
Expand Down
7 changes: 5 additions & 2 deletions src/pages-edit/sign-up/components/university.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useAppSelector } from "src/hooks/useReduxHooks";
import { useUserMutation } from "src/hooks/account/useUserMutation";
import useGetUnivQuery from "src/hooks/school/useGetUnivQuery";
import useGetMajorQuery from "src/hooks/school/useGetMajorQuery";
import { useUserQuery } from "src/hooks/account/useUserQuery";

import Flex from "src/components/common/Flex";
import InputLine from "src/components/inputs/input-line";
Expand All @@ -18,8 +19,10 @@ import { Route } from "src/constants/Route";

const University = () => {
const router = useRouter();
const school = useInput();
const department = useInput();
const { user } = useUserQuery();

const school = useInput(user?.schoolName);
const department = useInput(user?.class);
const grade = useSelect("23학번");
const selected = useAppSelector((state) => state.organization.selected);

Expand Down
2 changes: 1 addition & 1 deletion src/pages-edit/sign-up/organization.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { useRouter } from "next/navigation";
import NavigationTop from "src/components/navigations/NavigationTopBack";
import NavigationTop from "src/components/navigations/NavigationTop";
import Flex from "src/components/common/Flex";
import SelectBox from "src/components/selectbox/selectbox";
import { ORGANIZATION_OPTIONS } from "src/constants/options";
Expand Down