Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isSinitto 속성에 맞게 페이지 이동 #216

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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