Skip to content

Commit

Permalink
🐛 fix: sessionProvider에 불필요한 hook, session 코드 삭제 #53
Browse files Browse the repository at this point in the history
  • Loading branch information
froggy1014 committed Oct 7, 2024
1 parent 22ae3ef commit 8518502
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
5 changes: 1 addition & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Metadata } from "next";
import Script from "next/script";
import { ReactNode } from "react";

import { auth } from "@/auth";
import { env } from "@/env";
import MobileLayout from "@/layout/Mobile/MobileLayout";
import {
Expand All @@ -27,12 +26,10 @@ export default async function RootLayout({
}: Readonly<{
children: ReactNode;
}>) {
const session = await auth();

return (
<html lang="ko" className={Pretendard.variable}>
<body className={cn(Pretendard.className)} suppressHydrationWarning>
<SessionProvider session={session}>
<SessionProvider>
<MSWProvider>
<ReactQueryProvider>
<MobileLayout>
Expand Down
22 changes: 0 additions & 22 deletions src/hooks/session/useInitializeUserProfile.tsx

This file was deleted.

27 changes: 19 additions & 8 deletions src/lib/Providers/SessionProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
"use client";

import { Session } from "next-auth";
import { SessionProvider as AuthProvider } from "next-auth/react";
import { FC } from "react";
import { getSession, SessionProvider as AuthProvider } from "next-auth/react";
import { FC, useEffect } from "react";

import useInitializeUserProfile from "@/hooks/session/useInitializeUserProfile";
import { useUserStore } from "@/store/user";

interface Props {
children: React.ReactNode;
session: Session | null;
}

const SessionProvider: FC<Props> = ({ children, session }) => {
useInitializeUserProfile(session);
return <AuthProvider session={session}>{children}</AuthProvider>;
const SessionProvider: FC<Props> = ({ children }) => {
const setUser = useUserStore((state) => state.updateUser);

const initializeUserProfile = async () => {
const session = await getSession();
if (session) {
const { user } = session;
return setUser(user);
}
setUser(null);
};

useEffect(() => {
initializeUserProfile();
}, []);
return <AuthProvider>{children}</AuthProvider>;
};

export default SessionProvider;

0 comments on commit 8518502

Please sign in to comment.