Files
height_manager/client/contexts/AuthContext.tsx

50 lines
1.4 KiB
TypeScript
Raw Normal View History

// @ts-nocheck
/**
*
*
* API
* 使 @api api
*
*
* - / login/logouttoken
* -
*/
import React, { createContext, useContext, ReactNode } from "react";
interface UserOut {
}
interface AuthContextType {
user: UserOut | null;
token: string | null;
isAuthenticated: boolean;
isLoading: boolean;
login: (token: string) => Promise<void>;
logout: () => Promise<void>;
updateUser: (userData: Partial<UserOut>) => void;
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const value: AuthContextType = {
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
login: async (token: string) => {},
logout: async () => {},
updateUser: () => {},
};
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
};
export const useAuth = (): AuthContextType => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
};