54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
export enum AuthStatus
|
|
{
|
|
disconnected, loading, connected
|
|
};
|
|
export interface Auth
|
|
{
|
|
id: Ref<number>;
|
|
data: Ref<Record<string, any>>;
|
|
token: Ref<string>;
|
|
session_id: Ref<number>;
|
|
status: Ref<AuthStatus>;
|
|
|
|
lastRefresh: Ref<Date>;
|
|
|
|
register: (username: string, email: string, password: string, data?: Record<string, any>) => AuthStatus;
|
|
login: (usernameOrEmail: string, password: string) => AuthStatus;
|
|
logout: () => AuthStatus;
|
|
|
|
refresh: () => AuthStatus;
|
|
}
|
|
|
|
const id = useState<number>("auth:id", () => 0);
|
|
const data = useState<any>("auth:data", () => {});
|
|
const token = useState<string>("auth:token", () => '');
|
|
const session_id = useState<number>("auth:session_id", () => 0);
|
|
const status = useState<AuthStatus>("auth:status", () => 0);
|
|
|
|
const lastRefresh = useState<Date>("auth:date", () => new Date());
|
|
|
|
function register(username: string, email: string, password: string, data?: Record<string, any>): AuthStatus
|
|
{
|
|
|
|
return AuthStatus.disconnected;
|
|
}
|
|
function login(usernameOrEmail: string, password: string): AuthStatus
|
|
{
|
|
return AuthStatus.disconnected;
|
|
}
|
|
function logout(): AuthStatus
|
|
{
|
|
return AuthStatus.disconnected;
|
|
}
|
|
|
|
function refresh(): AuthStatus
|
|
{
|
|
return AuthStatus.disconnected;
|
|
}
|
|
|
|
export default function useAuth(): Auth {
|
|
return {
|
|
id, data, token, session_id, status, lastRefresh,
|
|
register, login, logout, refresh
|
|
};
|
|
} |