Files
o2o-weather/frontend/src/b/authContext.ts
T
minaChoi 2ab2271d61 refactor: 웹·앱 공통 코드를 shared 패키지로 분리 (npm workspaces)
- API 클라이언트·토큰 갱신·순수 함수를 shared/ (@nalssigak/shared) 로 옮김
- 토큰 저장소·API 주소는 configureApi 로 플랫폼에서 넣는다 (웹 localStorage)
- 루트 package.json 에 frontend·mobile·shared workspaces, lock 파일 하나로
- 웹 Docker 빌드 대상을 저장소 루트로 (compose context ., 루트 .dockerignore)
2026-10-14 14:27:47 +09:00

14 lines
528 B
TypeScript

import { createContext, use } from 'react'
import type { Me } from '@nalssigak/shared/api/client/types.gen'
/** mePending: 토큰은 있고 내 정보를 받는 중 (아바타 자리를 비워 두지 않으려고) */
export type AuthApi = { loggedIn: boolean; me: Me | null; mePending: boolean; logout: () => void }
export const AuthContext = createContext<AuthApi | null>(null)
export function useAuth() {
const ctx = use(AuthContext)
if (!ctx) throw new Error('useAuth must be used inside AuthProvider')
return ctx
}