feat: login

This commit is contained in:
tbphp
2025-07-02 19:14:23 +08:00
parent c7d54db31a
commit 8e1de8d29f
10 changed files with 216 additions and 9 deletions

33
web/src/services/auth.ts Normal file
View File

@@ -0,0 +1,33 @@
import http from "@/utils/http";
const AUTH_KEY = "authKey";
const login = async (authKey: string): Promise<boolean> => {
try {
await http.post("/auth/login", { auth_key: authKey });
localStorage.setItem(AUTH_KEY, authKey);
return true;
} catch (error) {
console.error("Login failed:", error);
return false;
}
};
const logout = (): void => {
localStorage.removeItem(AUTH_KEY);
};
const getAuthKey = (): string | null => {
return localStorage.getItem(AUTH_KEY);
};
const isLoggedIn = (): boolean => {
return !!localStorage.getItem(AUTH_KEY);
};
export const authService = {
login,
logout,
getAuthKey,
isLoggedIn,
};