Skip to content

Commit

Permalink
FE: [feat] 로그인 유저 검증 후 렌더링 #66
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeona01 committed Nov 26, 2024
1 parent 4490d1e commit fb4d8cf
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/frontend/eyesee-admin/src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { getAccessToken } from "@/utils/auth";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactNode } from "react";
import { usePathname, useRouter } from "next/navigation";
import { ReactNode, useEffect } from "react";

function makeQueryClient() {
return new QueryClient({
Expand Down Expand Up @@ -32,6 +34,23 @@ type ProvidersProps = {

export default function Providers({ children }: ProvidersProps) {
const queryClient = getQueryClient();
const accessToken = getAccessToken();

const pathname = usePathname();
const router = useRouter();

// 로그인 여부를 검증하여 페이지 렌더링
useEffect(() => {
if (
!accessToken &&
pathname != "/signin" &&
pathname !== "/signup" &&
pathname !== "/"
) {
alert("로그인이 필요합니다.");
router.push("/signin");
}
}, [pathname]);

return (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
Expand Down

0 comments on commit fb4d8cf

Please sign in to comment.