Refactor: api, 세션 스토리지 기준으로 변경
This commit is contained in:
parent
4aa1dee1e9
commit
07cbe72ba9
@ -30,7 +30,7 @@ const processQueue = (error: Error | null, token: string | undefined = undefined
|
||||
};
|
||||
|
||||
api.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||
const token = localStorage.getItem('accessToken');
|
||||
const token = sessionStorage.getItem('accessToken');
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
@ -72,7 +72,7 @@ api.interceptors.response.use(
|
||||
}
|
||||
|
||||
useAuthStore.getState().setLoggedIn(true, newAccessToken);
|
||||
localStorage.setItem('accessToken', newAccessToken);
|
||||
sessionStorage.setItem('accessToken', newAccessToken);
|
||||
processQueue(null, newAccessToken);
|
||||
|
||||
if (originalRequest.headers) {
|
||||
|
@ -1,18 +1,13 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
interface ProfileData {
|
||||
id: number | null;
|
||||
nickname: string;
|
||||
profileImage: string;
|
||||
}
|
||||
import { MemberResponseDTO } from '@/types';
|
||||
|
||||
interface AuthState {
|
||||
isLoggedIn: boolean;
|
||||
accessToken: string;
|
||||
profile: ProfileData;
|
||||
profile: MemberResponseDTO | null;
|
||||
setLoggedIn: (status: boolean, token: string) => void;
|
||||
setProfile: (profile: ProfileData) => void;
|
||||
setProfile: (profile: MemberResponseDTO) => void;
|
||||
clearAuth: () => void;
|
||||
}
|
||||
|
||||
@ -21,15 +16,14 @@ const useAuthStore = create<AuthState>()(
|
||||
(set) => ({
|
||||
isLoggedIn: false,
|
||||
accessToken: '',
|
||||
profile: { id: null, nickname: '', profileImage: '' },
|
||||
profile: null,
|
||||
setLoggedIn: (status, token) => set({ isLoggedIn: status, accessToken: token }),
|
||||
setProfile: (profile) => set({ profile }),
|
||||
clearAuth: () =>
|
||||
set({ isLoggedIn: false, accessToken: '', profile: { id: null, nickname: '', profileImage: '' } }),
|
||||
clearAuth: () => set({ isLoggedIn: false, accessToken: '', profile: null }),
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage',
|
||||
getStorage: () => localStorage,
|
||||
getStorage: () => sessionStorage,
|
||||
}
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user