diff --git a/src/@types/user.d.ts b/src/@types/user.d.ts index e4bfaed7..b11e4b4c 100644 --- a/src/@types/user.d.ts +++ b/src/@types/user.d.ts @@ -148,7 +148,7 @@ declare namespace User { export interface SignInRequestDto { email: string; password: string; - //auto?: boolean; + auto?: boolean; } export interface IsDuplicatedEmailResponseDto { diff --git a/src/configs/axios.ts b/src/configs/axios.ts index edb63864..4eb6bac0 100644 --- a/src/configs/axios.ts +++ b/src/configs/axios.ts @@ -16,15 +16,19 @@ export const resetAccess = (): unknown => delete API.defaults.headers['Authoriza //Refresh const storageRefreshKey = 'CAUCSE_JWT_REFRESH'; +let isStored: boolean = true; -export const storeRefresh = (token: string): void => { - localStorage.setItem(storageRefreshKey, token); +export const storeRefresh = (auto: boolean, token: string): void => { + isStored = auto; + if (isStored) localStorage.setItem(storageRefreshKey, token); + else sessionStorage.setItem(storageRefreshKey, token); }; export const removeRefresh = (): void => { localStorage.removeItem(storageRefreshKey); + sessionStorage.removeItem(storageRefreshKey); }; export const getRefresh = (): string | null => { - return localStorage.getItem(storageRefreshKey); + return localStorage.getItem(storageRefreshKey) ?? sessionStorage.getItem(storageRefreshKey); }; API.interceptors.response.use( @@ -51,7 +55,7 @@ API.interceptors.response.use( setAccess(accessToken); removeRefresh(); - storeRefresh(refreshToken); + storeRefresh(isStored, refreshToken); config.headers['Authorization'] = accessToken; return API.request(config); diff --git a/src/pages/auth/signIn/SignInPage.tsx b/src/pages/auth/signIn/SignInPage.tsx index d97d51e0..a3e4b91d 100644 --- a/src/pages/auth/signIn/SignInPage.tsx +++ b/src/pages/auth/signIn/SignInPage.tsx @@ -34,6 +34,7 @@ const SignInPage: React.FC = observer(() => { defaultValues: { email: '', password: '', + auto: true, }, }); const onSubmit = async (body: User.SignInRequestDto) => { @@ -69,6 +70,16 @@ const SignInPage: React.FC = observer(() => { )} /> + ( + } + /> + )} + /> 로그인 diff --git a/src/stores/repositories/AuthRepo.ts b/src/stores/repositories/AuthRepo.ts index 0017e164..a70906c5 100644 --- a/src/stores/repositories/AuthRepo.ts +++ b/src/stores/repositories/AuthRepo.ts @@ -2,7 +2,7 @@ import { AxiosResponse } from 'axios'; import { UserModel } from '../models/UserModel'; -import { API, setAccess, storeRefresh, removeRefresh } from '@/configs/axios'; +import { API, setAccess, storeRefresh } from '@/configs/axios'; class AuthRepo { URI = '/api/v1/users'; @@ -16,7 +16,7 @@ class AuthRepo { }>; setAccess(accessToken); - storeRefresh(refreshToken); + storeRefresh(body.auto ?? false, refreshToken); }; isDuplicatedEmail = async (email: string): Promise => {