"use client"; import React, { createContext, useContext, useEffect, useState, useCallback, } from "react"; import { oauthLoginUrl, oauthHandleRedirectIfPresent, type OAuthResult, } from "@huggingface/hub"; import { AUTH_STORAGE_KEY } from "@/utils/auth"; interface OAuthAppConfig { clientId: string; scopes: string; } interface AuthContextValue { oauth: OAuthResult | null; // Whether OAuth is configured for this deployment. Determined by hitting // /api/auth/config — the server reads OAUTH_CLIENT_ID from its env, which // HF Spaces injects when `hf_oauth: true` is set in the README. When // unconfigured, the button hides itself. isAuthAvailable: boolean; signIn: () => Promise; signOut: () => void; } const AuthContext = createContext({ oauth: null, isAuthAvailable: false, signIn: async () => {}, signOut: () => {}, }); // Mirror the access token into an HttpOnly cookie so the same-origin // /api/proxy route can attach it to