From 527d661a1b1a12a26b70bb7ce84c7480b610f44c Mon Sep 17 00:00:00 2001 From: dorimu0 <121004915+dorimu0@users.noreply.github.com> Date: Wed, 23 Oct 2024 20:05:31 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20:=20Update=20Go?= =?UTF-8?q?ogle=20Login=20page=20for=20client-side=20rendering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified the Google Login page to use URLSearchParams for obtaining the 'code' parameter from the URL. - Implemented `getServerSideProps` to disable static generation, ensuring the page renders on the client side. - Added error handling for login response to improve user state management and cookie handling. Related issue: #129 --- src/app/googleLogin/page.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/googleLogin/page.tsx b/src/app/googleLogin/page.tsx index 5977000..f30481f 100644 --- a/src/app/googleLogin/page.tsx +++ b/src/app/googleLogin/page.tsx @@ -1,7 +1,7 @@ 'use client'; import {useEffect} from 'react'; import Image from 'next/image'; -import {useRouter, useSearchParams} from 'next/navigation'; +import {useRouter} from 'next/navigation'; import Cookies from 'js-cookie'; import {useSetRecoilState} from 'recoil'; import userState from '@/src/recoil/atoms/userState'; @@ -9,11 +9,16 @@ import postGoogleLogin from '@/src/api/auth/postGoogleLogin'; import gifs from '@/public/gif'; import '@/src/styles/variable.css'; +export const dynamic = 'force-dynamic'; // 이 페이지는 클라이언트 측에서만 렌더링됨 + const Page = () => { - const code: string | null = useSearchParams().get('code'); const setUser = useSetRecoilState(userState); const router = useRouter(); + useEffect(() => { + const params = new URLSearchParams(window.location.search); + const code = params.get('code'); + if (code) { postGoogleLogin(code).then(res => { if (res.user) { @@ -26,7 +31,7 @@ const Page = () => { router.push('/classes'); }); } - }, []); + }, [router, setUser]); return (