- SpaceWorkspaceWidget 로직을 전용 훅 및 유틸리티로 분리 (900줄 -> 300줄) - useSpaceWorkspaceSelection 훅을 기능별(영속성, 진단 등) 소형 훅으로 분리 - SpaceToolsDockWidget의 상태 및 핸들러 로직 추출 - 거대 i18n 번역 파일(ko.ts)을 도메인별 메시지 파일로 구조화 - AdminConsoleWidget 누락분 추가 및 미디어 엔티티 타입 오류 수정
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { create } from 'zustand';
|
|
import Cookies from 'js-cookie';
|
|
import type { AuthResponse } from '@/entities/auth';
|
|
import { REFRESH_TOKEN_COOKIE_KEY, TOKEN_COOKIE_KEY } from '@/shared/config/authTokens';
|
|
|
|
interface AuthState {
|
|
accessToken: string | null;
|
|
user: AuthResponse['user'] | null;
|
|
isAuthenticated: boolean;
|
|
|
|
// 액션
|
|
setAuth: (data: AuthResponse) => void;
|
|
logout: () => void;
|
|
}
|
|
|
|
/**
|
|
* VibeRoom 전역 인증(Auth) 상태 저장소
|
|
*/
|
|
export const useAuthStore = create<AuthState>((set) => {
|
|
const isClient = typeof window !== 'undefined';
|
|
const savedToken = isClient ? Cookies.get(TOKEN_COOKIE_KEY) : null;
|
|
|
|
return {
|
|
accessToken: savedToken || null,
|
|
user: null,
|
|
isAuthenticated: !!savedToken,
|
|
|
|
setAuth: (data: AuthResponse) => {
|
|
const cookieOptions = {
|
|
secure: process.env.NODE_ENV === 'production',
|
|
sameSite: 'strict' as const
|
|
};
|
|
|
|
// 1. Access Token 저장 (7일)
|
|
Cookies.set(TOKEN_COOKIE_KEY, data.accessToken, {
|
|
...cookieOptions,
|
|
expires: 7
|
|
});
|
|
|
|
// 2. Refresh Token 저장 (30일)
|
|
if (data.refreshToken) {
|
|
Cookies.set(REFRESH_TOKEN_COOKIE_KEY, data.refreshToken, {
|
|
...cookieOptions,
|
|
expires: 30
|
|
});
|
|
}
|
|
|
|
// 3. 상태 업데이트
|
|
set({
|
|
accessToken: data.accessToken,
|
|
user: data.user,
|
|
isAuthenticated: true
|
|
});
|
|
},
|
|
|
|
logout: () => {
|
|
Cookies.remove(TOKEN_COOKIE_KEY);
|
|
Cookies.remove(REFRESH_TOKEN_COOKIE_KEY);
|
|
|
|
set({
|
|
accessToken: null,
|
|
user: null,
|
|
isAuthenticated: false
|
|
});
|
|
},
|
|
};
|
|
});
|