Extract memind_adm admin server, add local dev tooling, and remove image-generation.
Split platform admin and ops APIs into standalone admin-server.mjs with network guards; simplify billing to RMB token pricing, refactor user auth, and add rsync deploy plus local-test scripts and docs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
|
||||
export type AuthUser = {
|
||||
id: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
role: string;
|
||||
status?: string;
|
||||
};
|
||||
|
||||
type AuthState = { loading: boolean; user: AuthUser | null };
|
||||
|
||||
const AuthContext = createContext<AuthState>({ loading: true, user: null });
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const [state, setState] = useState<AuthState>({ loading: true, user: null });
|
||||
|
||||
useEffect(() => {
|
||||
void fetch('/auth/status', { credentials: 'include' })
|
||||
.then((r) => r.json())
|
||||
.then((auth: { authenticated: boolean; user?: AuthUser }) => {
|
||||
setState({ loading: false, user: auth.authenticated ? (auth.user ?? null) : null });
|
||||
})
|
||||
.catch(() => setState({ loading: false, user: null }));
|
||||
}, []);
|
||||
|
||||
return <AuthContext.Provider value={state}>{children}</AuthContext.Provider>;
|
||||
}
|
||||
|
||||
export const useAuth = () => useContext(AuthContext);
|
||||
Reference in New Issue
Block a user