Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| export { COOKIE_NAME, ONE_YEAR_MS } from "@shared/const"; | |
| // Auth configuration type | |
| export type AuthConfig = { | |
| hfOAuthEnabled: boolean; | |
| devLoginEnabled: boolean; | |
| }; | |
| // Fetch auth config from server | |
| let cachedAuthConfig: AuthConfig | null = null; | |
| export const getAuthConfig = async (): Promise<AuthConfig> => { | |
| if (cachedAuthConfig) return cachedAuthConfig; | |
| try { | |
| const response = await fetch("/api/auth/config"); | |
| cachedAuthConfig = await response.json(); | |
| return cachedAuthConfig!; | |
| } catch { | |
| return { hfOAuthEnabled: false, devLoginEnabled: true }; | |
| } | |
| }; | |
| // Get login URL based on available auth methods | |
| export const getLoginUrl = (): string => { | |
| const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL; | |
| const appId = import.meta.env.VITE_APP_ID; | |
| // If standard OAuth is configured, use it | |
| if (oauthPortalUrl && appId) { | |
| const redirectUri = `${window.location.origin}/api/oauth/callback`; | |
| const state = btoa(redirectUri); | |
| const url = new URL(`${oauthPortalUrl}/app-auth`); | |
| url.searchParams.set("appId", appId); | |
| url.searchParams.set("redirectUri", redirectUri); | |
| url.searchParams.set("state", state); | |
| url.searchParams.set("type", "signIn"); | |
| return url.toString(); | |
| } | |
| // Return placeholder - frontend will check auth config for alternatives | |
| return "#oauth-not-configured"; | |
| }; | |
| // Get HuggingFace login URL | |
| export const getHfLoginUrl = (): string => "/api/hf/login"; | |
| // Get dev login URL | |
| export const getDevLoginUrl = (): string => "/api/dev/login"; | |