Skip to content

Commit

Permalink
isSinitto 속성에 맞게 페이지 이동 (#216)
Browse files Browse the repository at this point in the history
isSinitto 속성에 맞게 페이지 이동
  • Loading branch information
Dobbymin authored Nov 14, 2024
2 parents 9dbbc65 + 220236a commit 7292a80
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {

const ProtectedRoute = ({ requiresAuth, sinittoOnly, guardOnly }: Props) => {
const accessToken = authStorage.accessToken.get();
const isSinitto = authStorage.isSinitto.get() === true;
const isSinitto = authStorage.isSinitto.get() === 'true';

if (requiresAuth && !accessToken) {
return <Navigate to={RouterPath.ROOT} />;
Expand Down
14 changes: 8 additions & 6 deletions src/pages/common/dummy-redirect/DummyRedirectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@ export const DummyRedirectPage = () => {
const refreshToken = params.get('refreshToken');
const isSinitto = params.get('isSinitto');

if (accessToken && refreshToken && isSinitto) {
if (accessToken && refreshToken && isSinitto !== null) {
// 로컬 스토리지에 토큰 저장
authStorage.accessToken.set(accessToken);
authStorage.refreshToken.set(refreshToken);
authStorage.isSinitto.set(isSinitto === 'true');
authStorage.isSinitto.set(isSinitto);

// isSinitto 상태에 따른 메시지 설정
setStatusMessage(
isSinitto === 'true'
isSinitto
? '시니또 더미데이터로 로그인 중입니다. 페이지 이동 중...'
: '보호자 더미데이터로 로그인 중입니다. 페이지 이동 중...'
);

setTimeout(() => {
setIsLoading(false); // 로딩 완료
navigate(isSinitto === 'true' ? RouterPath.SINITTO : RouterPath.GUARD);
navigate(isSinitto ? RouterPath.SINITTO : RouterPath.GUARD);
}, 2000);
} else {
console.error('Access or Refresh token not found in query parameters.');
setStatusMessage('[ERROR] 토큰이 존재하지 않습니다.');
console.error(
'Access or Refresh token not found in query parameters or isSinitto is invalid.'
);
setStatusMessage('[ERROR] 유효하지 않은 토큰 또는 파라미터입니다.');

setIsLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const RedirectSection = ({ code }: Props) => {

authStorage.accessToken.set(accessToken);
authStorage.refreshToken.set(refreshToken);
authStorage.isSinitto.set(isSinitto);
authStorage.isSinitto.set(isSinitto.toString());

setEmail(data.email);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/common/register/ui/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const RegisterPage = () => {
isSinitto,
};

authStorage.isSinitto.set(requestData.isSinitto);
authStorage.isSinitto.set(requestData.isSinitto.toString());

mutation.mutate(requestData);
};
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/storage/authStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type StorageKey = {
accessToken?: string;
refreshToken?: string;
isSinitto?: boolean;
isSinitto?: string;
};

const initStorage = <T extends keyof StorageKey>(
Expand Down

0 comments on commit 7292a80

Please sign in to comment.