Spaces:
Running
Running
Download web/src/lib/auth-session.ts from li2895/chatgpt2api: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/li2895/chatgpt2api/resolve/main/web/src/lib/auth-session.ts
- Command line
-
hf download hf://spaces/li2895/chatgpt2api/web/src/lib/auth-session.ts
-
curl -L -o auth-session.ts https://huggingface.co/spaces/li2895/chatgpt2api/resolve/main/web/src/lib/auth-session.ts
718 Bytes
| "use client"; | |
| import { login } from "@/lib/api"; | |
| import { clearStoredAuthSession, getStoredAuthSession, setStoredAuthSession, type StoredAuthSession } from "@/store/auth"; | |
| export async function getValidatedAuthSession(): Promise<StoredAuthSession | null> { | |
| const storedSession = await getStoredAuthSession(); | |
| if (!storedSession) { | |
| return null; | |
| } | |
| try { | |
| const data = await login(storedSession.key); | |
| const nextSession: StoredAuthSession = { | |
| key: storedSession.key, | |
| role: data.role, | |
| subjectId: data.subject_id, | |
| name: data.name, | |
| }; | |
| await setStoredAuthSession(nextSession); | |
| return nextSession; | |
| } catch { | |
| await clearStoredAuthSession(); | |
| return null; | |
| } | |
| } | |