Skip to content

Commit

Permalink
refactor: 함수 이름 변경 getAuth -> getDecodedToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiwon-Woo committed Dec 20, 2023
1 parent 23ffccc commit 8fe342c
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/cert/TokenStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
6 changes: 3 additions & 3 deletions src/components/Auth/AuthCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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('/');
Expand Down
4 changes: 2 additions & 2 deletions src/components/Review/SelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReviewSelectedEventType[]>(
Expand Down Expand Up @@ -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);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Rotation/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,7 +21,7 @@ const COLOR = {

export default class Calendar extends React.Component {
state = {
auth: getAuth(),
auth: getDecodedToken(),
weekendsVisible: true,
currentEvents: [],
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Rotation/Rotation.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Rotation/RotationResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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로 변경하여 로딩화면 띄우기
Expand Down
4 changes: 2 additions & 2 deletions src/components/Rotation/event_utils.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) => ({
Expand Down
4 changes: 2 additions & 2 deletions src/globalObj/object/EmptyEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAuth } from '@cert/AuthStorage';
import { getDecodedToken } from '@cert/TokenStorage';
import { ReviewSelectedEventType } from './types';

function EmptyEvent(): ReviewSelectedEventType {
Expand All @@ -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 }] },
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/recoil/GlobalLoginState.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 8fe342c

Please sign in to comment.