Skip to content

Commit

Permalink
Merge pull request #349 from Team-Lecue/bugfix/401
Browse files Browse the repository at this point in the history
[ BugFix ] 닉네임 설정 401 Error을 해결합니다.
  • Loading branch information
jungwoo3490 authored Aug 12, 2024
2 parents acadce2 + 1dc382d commit cf0ecd5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Login/hooks/usePostLoginToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/Login/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<S.LoginWrapper>
<Header />
Expand Down
3 changes: 2 additions & 1 deletion src/Register/api/patchNickname.ts
Original file line number Diff line number Diff line change
@@ -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}`,
},
},
);
Expand Down
5 changes: 3 additions & 2 deletions src/Register/hooks/usePatchNickname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 } });
},
Expand Down

0 comments on commit cf0ecd5

Please sign in to comment.