미사용 파일정리
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { create } from 'zustand'; // Zustand 상태 관리 라이브러리
|
||||
import { persist } from 'zustand/middleware'; // Zustand 상태 영속화 미들웨어
|
||||
// TypeScript/Node 모듈 규칙 - 폴더를 import 하면 자동으로 그 안의 index 파일을 찾는 규칙
|
||||
import { authApi } from '@/lib/api'; // tsconfig.json의 paths 규칙에 따라 절대경로 import
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { authApi } from '@/lib/api/auth.api';
|
||||
import { UserDto, LoginDto, SignupDto } from '@/types/auth.types';
|
||||
|
||||
/**
|
||||
@@ -12,8 +11,7 @@ import { UserDto, LoginDto, SignupDto } from '@/types/auth.types';
|
||||
interface AuthState {
|
||||
// 상태
|
||||
user: UserDto | null; // 현재 로그인한 사용자 정보
|
||||
accessToken: string | null; // JWT 액세스 토큰
|
||||
refreshToken: string | null; // JWT 리프레시 토큰
|
||||
accessToken: string | null; // JWT 액세스 토큰 (24시간 유효)
|
||||
isAuthenticated: boolean; // 로그인 여부
|
||||
|
||||
|
||||
@@ -21,7 +19,6 @@ interface AuthState {
|
||||
login: (dto: LoginDto) => Promise<void>; // 로그인
|
||||
signup: (dto: SignupDto) => Promise<void>; // 회원가입
|
||||
logout: () => Promise<void>; // 로그아웃
|
||||
refreshAuth: () => Promise<void>; // 토큰 갱신
|
||||
loadProfile: () => Promise<void>; // 프로필 불러오기
|
||||
clearAuth: () => void; // 인증 정보 초기화 (클라이언트에서)
|
||||
}
|
||||
@@ -45,7 +42,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
// 초기 상태
|
||||
user: null,
|
||||
accessToken: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
|
||||
/**
|
||||
@@ -54,18 +50,13 @@ export const useAuthStore = create<AuthState>()(
|
||||
*/
|
||||
login: async (dto: LoginDto) => {
|
||||
try {
|
||||
const response = await authApi.login(dto); // authApi의 login 함수 호출
|
||||
//authApi는 auth.api.ts에 정의되어 있음
|
||||
//import { authApi } from '@/lib/api'; 임포트를 @/lib/api 로 했기 때문에
|
||||
//자동으로 index.ts를 찾아가서 authApi를 가져옴
|
||||
//직접 auth.api.ts를 import 하려면 '@/lib/api/auth.api'로 해야함
|
||||
|
||||
const response = await authApi.login(dto);
|
||||
|
||||
// 받아온 결과를 상태에 저장
|
||||
// Zustand 상태 업데이트 (persist 미들웨어가 자동으로 localStorage에 저장)
|
||||
set({
|
||||
set({
|
||||
user: response.user,
|
||||
accessToken: response.accessToken,
|
||||
refreshToken: response.refreshToken || null,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -85,7 +76,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
set({
|
||||
user: response.user,
|
||||
accessToken: response.accessToken,
|
||||
refreshToken: response.refreshToken || null,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -107,39 +97,11 @@ export const useAuthStore = create<AuthState>()(
|
||||
set({
|
||||
user: null,
|
||||
accessToken: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 토큰 갱신
|
||||
*/
|
||||
refreshAuth: async () => {
|
||||
try {
|
||||
const { refreshToken } = get();
|
||||
|
||||
if (!refreshToken) {
|
||||
throw new Error('리프레시 토큰이 없습니다.');
|
||||
}
|
||||
|
||||
const response = await authApi.refreshToken(refreshToken);
|
||||
|
||||
// Zustand 상태 업데이트 (persist 미들웨어가 자동으로 localStorage에 저장)
|
||||
set({
|
||||
user: response.user,
|
||||
accessToken: response.accessToken,
|
||||
refreshToken: response.refreshToken || refreshToken,
|
||||
isAuthenticated: true,
|
||||
});
|
||||
} catch (error) {
|
||||
// 토큰 갱신 실패 시 로그아웃 처리
|
||||
get().clearAuth();
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 프로필 불러오기
|
||||
*/
|
||||
@@ -165,7 +127,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
set({
|
||||
user: null,
|
||||
accessToken: null,
|
||||
refreshToken: null,
|
||||
isAuthenticated: false,
|
||||
});
|
||||
},
|
||||
@@ -176,7 +137,6 @@ export const useAuthStore = create<AuthState>()(
|
||||
// localStorage에 저장할 필드만 선택
|
||||
user: state.user,
|
||||
accessToken: state.accessToken,
|
||||
refreshToken: state.refreshToken,
|
||||
isAuthenticated: state.isAuthenticated,
|
||||
}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user