Skip to content

Commit

Permalink
Merge branch 'feature/DEV-96' of github.com-A:YAPP-Github/24th-Web-Te…
Browse files Browse the repository at this point in the history
…am-1-FE into feature/DEV-96
  • Loading branch information
Happhee committed Aug 20, 2024
2 parents 66b0720 + b44ef2a commit 97e1c66
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 49 deletions.
3 changes: 3 additions & 0 deletions src/app/auth/validation/complete/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter, useSearchParams } from "next/navigation";

import LottieClient from "@shared/components/Lottie";
import { Button } from "@shared/components/ui/button";

import useIsLogin from "@shared/hooks/useIsLogin";

import { SIGNUP_COMPLETED } from "@auth/constants/auth";
Expand All @@ -14,7 +15,9 @@ export default function ValidationCompletePage() {
const searchParams = useSearchParams();
const router = useRouter();
const memberEmail = searchParams.get("member_email");

const isLogin = useIsLogin();

return (
<div className="flex h-auto flex-col items-center">
<LottieClient animationData={lottieJson} />
Expand Down
3 changes: 1 addition & 2 deletions src/auth/hooks/useLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { deleteCookie } from "cookies-next";
import { ApiResponse } from "@api/fewFetch";

import { COOKIES } from "@shared/constants/token";
import { Mixpanel } from "@shared/utils/mixpanel";

import { logOutMutaionOption } from "@auth/remotes/logoutMembersQueryOption";

Expand All @@ -23,7 +22,7 @@ export const useLogout = () => {
// 쿠키 삭제 및 로그인 페이지로 이동
deleteCookie(COOKIES.REFRESH_TOKEN);
deleteCookie(COOKIES.ACCESS_TOKEN);
Mixpanel.reset();
// Mixpanel.reset();
router.push("/");
window.location.reload();
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/components/WorkbookCardDetail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { WorkbookCardClientInfo } from "@main/types/workbook";
import { Button } from "@shared/components/ui/button";
import { cn } from "@shared/utils/cn";
import Image, { ImageLoaderProps } from "next/image";
import Image from "next/image";
import FewLogo from "public/assets/icon/cardFewLogo.svg";

const ImageLoadr = ({ src, width, quality }: ImageLoaderProps) => {
return `${src}?w=${width}&q=${quality || 75}`;
};
const ImageWrapper = ({
children,
}: Readonly<{
Expand All @@ -22,8 +19,8 @@ const MainImage = ({
height={172}
src={mainImageUrl}
alt="main-image"
loader={ImageLoadr}
loading="lazy"
sizes="(max-width: 480px) 269px"
priority={isPriorityImage}
className="h-[172px] w-[269px] rounded-t-lg object-cover"
/>
);
Expand Down
1 change: 0 additions & 1 deletion src/main/models/ArticleCardModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default class ArticleCardModel {
thumbnail: this.webpBrowser.isWebpBrowser
? mainImageUrl
: ImageModel.changePngImage({ imageSrc: mainImageUrl }),

isPriorityImage: idx < 2,
title,
content: this.getRemoveTagContent({ content }),
Expand Down
2 changes: 1 addition & 1 deletion src/main/types/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type WorkbookCardServerInfo = {
export interface WorkbookCardClientInfo {
id: number;
mainImageUrl: string;
isPriorityImage: boolean;
isPriorityImage:boolean;
metaComponent: React.ReactElement;
title: string;
writers: string[];
Expand Down
1 change: 1 addition & 0 deletions src/problem/components/ProblemTitle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMutationState, useQuery } from "@tanstack/react-query";

import { ApiResponse } from "@api/fewFetch";


import { PROBLEM_TITLE_INFO } from "@problem/constants/problemInfo";
import { QUERY_KEY } from "@problem/remotes/api";
import { getProblemQueryOptions } from "@problem/remotes/getProblemQueryOptions";
Expand Down
68 changes: 29 additions & 39 deletions src/shared/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,42 @@ type authMiddlewareProps = {
};

export const AuthMiddleware = async ({ req, nextUrl }: authMiddlewareProps) => {
try {
const { searchParams } = nextUrl;
const auth_token = searchParams.get(AUTH_TOKEN);
if (auth_token) {
const response: ApiResponse<tokenResponse> = await fewFetch().post(
API_ROUTE.TOKEN(auth_token),
);

const authData = response.data;
const { searchParams } = nextUrl;
const auth_token = searchParams.get(AUTH_TOKEN);
if (auth_token) {
const response: ApiResponse<tokenResponse> = await fewFetch().post(
API_ROUTE.TOKEN(auth_token),
);

if (authData?.message === "알 수 없는 오류가 발생했어요.") {
nextUrl.searchParams.delete(AUTH_TOKEN);
const response = NextResponse.redirect(nextUrl);

response.cookies.set(ISLOGIN, "false");
const authData = response.data;

return NextResponse.redirect(nextUrl);
}
if (authData?.data?.accessToken) {
const accessToken = authData.data.accessToken;
const memberEmail = tokenParse(accessToken).memberEmail;
if (authData?.message === "알 수 없는 오류가 발생했어요.") {
nextUrl.searchParams.delete(AUTH_TOKEN);
const response = NextResponse.redirect(nextUrl);

nextUrl.searchParams.delete(AUTH_TOKEN);
nextUrl.searchParams.set("member_email", memberEmail);
response.cookies.set(ISLOGIN, "false");

const response = NextResponse.redirect(nextUrl);
return NextResponse.redirect(nextUrl);
}
if (authData?.data?.accessToken) {
const accessToken = authData.data.accessToken;
const memberEmail = tokenParse(accessToken).memberEmail;

nextUrl.searchParams.delete(AUTH_TOKEN);
nextUrl.searchParams.set("member_email", memberEmail);

const response = NextResponse.redirect(nextUrl);

response.cookies.set(COOKIES.ACCESS_TOKEN, authData?.data?.accessToken, {
maxAge: 24 * 60 * 60, // 30 days
});
response.cookies.set(COOKIES.REFRESH_TOKEN, authData?.data?.refreshToken, {
maxAge: 24 * 60 * 60, // 30 days
});

response.cookies.set(
COOKIES.ACCESS_TOKEN,
authData?.data?.accessToken,
{
maxAge: 24 * 60 * 60, // 30 days
},
);
response.cookies.set(
COOKIES.REFRESH_TOKEN,
authData?.data?.refreshToken,
{
maxAge: 24 * 60 * 60, // 30 days
},
);
return response;

return response;
}
}
} catch {
return undefined;
}
};

0 comments on commit 97e1c66

Please sign in to comment.