Skip to content

Commit

Permalink
feat: 전역에서 유저 인증 처리를 하기 위한 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Leejha committed Oct 11, 2023
1 parent 05986fa commit 1754092
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 0 additions & 2 deletions apps/chooz/lib/utils/userStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client";

export const USER_STORAGE_KEY = "CHOOZ_USER";

interface Token {
Expand Down
10 changes: 5 additions & 5 deletions apps/jurumarble/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Metadata } from "next";
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import { injectStyle } from "react-toastify/dist/inject-style";
import AuthProcess from "components/AuthProcess";

export const metadata: Metadata = {
title: "주루마블",
Expand All @@ -24,11 +25,10 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<ReactQueryProvider>
<StyledComponents>
<StyledLayout>
<>
<div id="portal" />
{children}
<ToastContainer position="top-center" autoClose={2000} hideProgressBar />
</>
<div id="portal" />
<AuthProcess />
{children}
<ToastContainer position="top-center" autoClose={2000} hideProgressBar />
</StyledLayout>
</StyledComponents>
</ReactQueryProvider>
Expand Down
4 changes: 0 additions & 4 deletions apps/jurumarble/src/app/my/components/UseInfoContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import styled, { css } from "styled-components";
import Image from "next/image";
import { DrinkImage } from "public/images";
import useGetUserInfo from "services/useGetUserInfo";
import { useRouter } from "next/navigation";

function UserInfoContainer() {
const { userInfo } = useGetUserInfo();
Expand All @@ -15,9 +14,6 @@ function UserInfoContainer() {

const { gender, nickname, yearOfBirth, mbti, imageUrl } = userInfo;

const router = useRouter();
if (!(gender && yearOfBirth && mbti)) router.replace(Path.REGISTER_PAGE);

const date = new Date();
const age = date.getFullYear() - yearOfBirth;
const ageRange = Math.floor(age / 10) * 10;
Expand Down
4 changes: 1 addition & 3 deletions apps/jurumarble/src/app/my/components/VoteItem.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Path from "lib/Path";
import { useRouter } from "next/navigation";
import { ExImg1 } from "public/images";
import useBookmarkService from "services/useBookmarkService";
import { Content } from "src/types/vote";
import styled, { css } from "styled-components";
import ChipContainer from "./ChipContainer";
import VoteDescription from "./VoteDescription";

type Props = Pick<Content, "voteId" | "region" | "title" | "imageA" | "imageB">;
const getSafeImage = (image: string) => (image.includes("http") ? image : ExImg1);

function VoteItem({ voteId, region, title, imageA, imageB }: Props) {
const { isBookmark, mutateBookMark } = useBookmarkService(voteId);
Expand All @@ -27,7 +25,7 @@ function VoteItem({ voteId, region, title, imageA, imageB }: Props) {
mutateBookMark={mutateBookMark}
isBookmark={isBookmark}
/>
<VoteDescription imageA={getSafeImage(imageA)} imageB={getSafeImage(imageB)} />
<VoteDescription imageA={imageA} imageB={imageB} />
</Container>
);
}
Expand Down
17 changes: 17 additions & 0 deletions apps/jurumarble/src/components/AuthProcess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client";

import { useRouter } from "next/navigation";
import useGetUserInfo from "services/useGetUserInfo";
import Path from "lib/Path";

function AuthProcess() {
const { userInfo } = useGetUserInfo();
if (!userInfo) return null;
const { gender, yearOfBirth, mbti } = userInfo!;
const router = useRouter();
if (!(gender && yearOfBirth && mbti)) router.replace(Path.REGISTER_PAGE);

return <></>;
}

export default AuthProcess;

0 comments on commit 1754092

Please sign in to comment.