diff --git a/src/Login/hooks/usePostLoginToken.ts b/src/Login/hooks/usePostLoginToken.ts index 9a4b9032..872d8805 100644 --- a/src/Login/hooks/usePostLoginToken.ts +++ b/src/Login/hooks/usePostLoginToken.ts @@ -14,7 +14,7 @@ const usePostLoginToken = () => { const { tokenDto, nickname } = data; if (nickname === null) { - navigate('/register', { state: tokenDto.accessToken }); + navigate('/register', { state: { tempToken: tokenDto.accessToken } }); } else { sessionStorage.setItem('token', tokenDto.accessToken); sessionStorage.setItem('nickname', nickname); diff --git a/src/Login/page/index.tsx b/src/Login/page/index.tsx index 6938af2e..2e3e27bd 100644 --- a/src/Login/page/index.tsx +++ b/src/Login/page/index.tsx @@ -5,9 +5,6 @@ import LoginBtnContainer from '../components/LoginBtnContainer'; import * as S from './Login.style'; function Login() { - const ref = document.referrer; - sessionStorage.setItem('url', ref); - return (
diff --git a/src/Register/api/patchNickname.ts b/src/Register/api/patchNickname.ts index ca9ae120..3406fc16 100644 --- a/src/Register/api/patchNickname.ts +++ b/src/Register/api/patchNickname.ts @@ -1,12 +1,13 @@ import { api } from '../../libs/api'; -export const patchNickname = async (nickname: string) => { +export const patchNickname = async (nickname: string, tempToken: string) => { const response = await api().patch( '/api/nickname', { nickname: nickname }, { headers: { 'Content-Type': 'application/json', + Authorization: `Bearer ${tempToken}`, }, }, ); diff --git a/src/Register/hooks/usePatchNickname.ts b/src/Register/hooks/usePatchNickname.ts index c97587e7..f27fcc68 100644 --- a/src/Register/hooks/usePatchNickname.ts +++ b/src/Register/hooks/usePatchNickname.ts @@ -11,12 +11,13 @@ import { const usePatchNickname = (props: usePatchNicknameProps) => { const { handleSetIsValid, handleSetIsActive, nickname } = props; const { state } = useLocation(); + const tempToken = state.tempToken; const navigate = useNavigate(); const mutation = useMutation({ mutationFn: async ({ nickname }: patchNicknameProps) => { - return await patchNickname(nickname); + return await patchNickname(nickname, tempToken); }, onError: (err: AxiosError) => { const code = err.response?.status; @@ -32,7 +33,7 @@ const usePatchNickname = (props: usePatchNicknameProps) => { } }, onSuccess: () => { - sessionStorage.setItem('token', state); + sessionStorage.setItem('token', state.tempToken); sessionStorage.setItem('nickname', nickname); navigate('/', { state: { step: 1 } }); },