diff --git a/src/cert/TokenStorage.ts b/src/cert/TokenStorage.ts index 135d95c..38a0e2e 100644 --- a/src/cert/TokenStorage.ts +++ b/src/cert/TokenStorage.ts @@ -74,7 +74,7 @@ export function getToken() { return token; } -export function getAuth(): { id: string; url: string } { +export function getDecodedToken(): { id: string; url: string } { const token = localStorage.getItem(TOKEN); if (!token) { return { id: null, url: null }; diff --git a/src/components/Auth/AuthCallback.tsx b/src/components/Auth/AuthCallback.tsx index 4bb02a8..d2431aa 100644 --- a/src/components/Auth/AuthCallback.tsx +++ b/src/components/Auth/AuthCallback.tsx @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'; import { useLocation } from 'react-router-dom'; import { saveToken } from '@cert/TokenStorage'; import { useNavigate } from 'react-router-dom'; -import { getAuth } from '@cert/TokenStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import GlobalLoginState from '@recoil/GlobalLoginState'; import { useSetRecoilState } from 'recoil'; @@ -17,10 +17,10 @@ const AuthCallback = () => { saveToken(token); setLoginState(() => { return { - id: getAuth().id, + id: getDecodedToken().id, isLogin: true, isAdmin: false, - profileUrl: getAuth().url, + profileUrl: getDecodedToken().url, }; }); navigate('/'); diff --git a/src/components/Review/SelectModal.tsx b/src/components/Review/SelectModal.tsx index 2d5c0df..d806442 100644 --- a/src/components/Review/SelectModal.tsx +++ b/src/components/Review/SelectModal.tsx @@ -12,7 +12,7 @@ import useSWR from 'swr'; import getAddress from '@globalObj/function/getAddress'; import fetcher from '@globalObj/function/fetcher'; import EmptyEvent from '@globalObj/object/EmptyEvent'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; function SelectModal(prop: { mode: string }) { const { data: eventList, mutate: mutateAllEvent } = useSWR( @@ -66,7 +66,7 @@ function SelectModal(prop: { mode: string }) { setSelectedTeam({ [event]: memArr }); setEventListModalShow(false); } else { - setSelectedTeam({ [event]: [{ intraId: getAuth().id, profile: getAuth().url, teamId: -1 }] }); + setSelectedTeam({ [event]: [{ intraId: getDecodedToken().id, profile: getDecodedToken().url, teamId: -1 }] }); setEventListModalShow(false); } }; diff --git a/src/components/Rotation/Calendar.tsx b/src/components/Rotation/Calendar.tsx index ce33353..6075ed1 100644 --- a/src/components/Rotation/Calendar.tsx +++ b/src/components/Rotation/Calendar.tsx @@ -10,7 +10,7 @@ import getAddress from '@globalObj/function/getAddress'; import { getToken } from '@cert/TokenStorage'; import errorAlert from '@globalObj/function/errorAlert'; import '@css/Rotation/Calendar.scss'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import { DAY_OF_SUNDAY } from './rotation_utils'; import apiClient from '@service/apiClient'; @@ -21,7 +21,7 @@ const COLOR = { export default class Calendar extends React.Component { state = { - auth: getAuth(), + auth: getDecodedToken(), weekendsVisible: true, currentEvents: [], }; diff --git a/src/components/Rotation/Rotation.tsx b/src/components/Rotation/Rotation.tsx index f25576c..e425bef 100644 --- a/src/components/Rotation/Rotation.tsx +++ b/src/components/Rotation/Rotation.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, MouseEvent } from 'react'; import { useNavigate } from 'react-router-dom'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import Calendar, { CalendarTileProperties } from 'react-calendar'; import getAddress from '@globalObj/function/getAddress'; import axios from 'axios'; @@ -325,7 +325,7 @@ export const Rotate = () => { const navigate = useNavigate(); const currentDate = new Date(); const initialRecord = createInitialObject(currentDate); - const intraId = getAuth()?.id ?? null; + const intraId = getDecodedToken()?.id ?? null; const isRotationApplicationPeriod = calculateIsRotationApplicationPeriod(currentDate); const [record, setRecord] = useState(() => ({ ...initialRecord })); const [isSubmit, setIsSumbit] = useState(false); diff --git a/src/components/Rotation/RotationResult.tsx b/src/components/Rotation/RotationResult.tsx index 5c03fa8..e1dc0fd 100644 --- a/src/components/Rotation/RotationResult.tsx +++ b/src/components/Rotation/RotationResult.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import LoadingSpinner from './Loading'; import { RotateUserResult } from './RotateUserResult'; import { getRotationMonthArr } from './event_utils'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import '@css/Rotation/Rotation.scss'; export const RotateResult = () => { @@ -13,7 +13,7 @@ export const RotateResult = () => { date < new Date(year, nextmonth, -1) ? (month = nextmonth - 1) : nextmonth; const [Loading, setLoading] = useState(true); const [arr, setArr] = useState([]); - const intraId = getAuth() ? getAuth().id : null; + const intraId = getDecodedToken() ? getDecodedToken().id : null; const mainApi = async () => { setLoading(true); // api 호출 전에 true로 변경하여 로딩화면 띄우기 diff --git a/src/components/Rotation/event_utils.tsx b/src/components/Rotation/event_utils.tsx index 23466fc..3ff5467 100644 --- a/src/components/Rotation/event_utils.tsx +++ b/src/components/Rotation/event_utils.tsx @@ -1,5 +1,5 @@ import getAddress from '@globalObj/function/getAddress'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import apiClient from '@service/apiClient'; import errorAlert from '@globalObj/function/errorAlert'; @@ -11,7 +11,7 @@ export function createEventId() { } function rotatedArrAllInfo(data) { - const intraId = getAuth() ? getAuth().id : null; + const intraId = getDecodedToken() ? getDecodedToken().id : null; return data .filter((el) => !!el.year && !!el.month && !!el.day) .map((el) => ({ diff --git a/src/globalObj/object/EmptyEvent.ts b/src/globalObj/object/EmptyEvent.ts index 2059be4..dc91ed5 100644 --- a/src/globalObj/object/EmptyEvent.ts +++ b/src/globalObj/object/EmptyEvent.ts @@ -1,4 +1,4 @@ -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; import { ReviewSelectedEventType } from './types'; function EmptyEvent(): ReviewSelectedEventType { @@ -9,7 +9,7 @@ function EmptyEvent(): ReviewSelectedEventType { createdId: 1, intraId: 'tkim', isMatching: 1, - teamList: { 사서: [{ intraId: getAuth().id, profile: getAuth().url, teamId: -1 }] }, + teamList: { 사서: [{ intraId: getDecodedToken().id, profile: getDecodedToken().url, teamId: -1 }] }, }; } diff --git a/src/recoil/GlobalLoginState.ts b/src/recoil/GlobalLoginState.ts index 43a8838..b61401e 100644 --- a/src/recoil/GlobalLoginState.ts +++ b/src/recoil/GlobalLoginState.ts @@ -1,13 +1,13 @@ import { atom } from 'recoil'; import { userData } from '@globalObj/object/types'; -import { getAuth } from '@cert/AuthStorage'; +import { getDecodedToken } from '@cert/TokenStorage'; -const value = getAuth() +const value = getDecodedToken() ? { isLogin: true, - isAdmin: getAuth()['id'] === 'tkim', - id: getAuth()['id'], - profileUrl: getAuth()['url'], + isAdmin: getDecodedToken()['id'] === 'tkim', + id: getDecodedToken()['id'], + profileUrl: getDecodedToken()['url'], } : { isLogin: false,