Keep map reads open; gate admin UI/nav and object mutations behind env-based admin credentials, and default parser batch limit to 10. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
938 B
TypeScript
42 lines
938 B
TypeScript
import { computed, ref } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { clearToken, getToken, isAuthenticated, login as doLogin, logout as doLogout } from "../auth";
|
|
|
|
export function useAuth() {
|
|
const router = useRouter();
|
|
const busy = ref(false);
|
|
const error = ref("");
|
|
|
|
const authenticated = computed(() => isAuthenticated.value);
|
|
|
|
async function login(username: string, password: string): Promise<boolean> {
|
|
busy.value = true;
|
|
error.value = "";
|
|
try {
|
|
await doLogin(username, password);
|
|
return true;
|
|
} catch (err) {
|
|
clearToken();
|
|
error.value = err instanceof Error ? err.message : "Не удалось войти";
|
|
return false;
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
|
|
function logout(): void {
|
|
doLogout();
|
|
void router.push({ name: "map" });
|
|
}
|
|
|
|
return {
|
|
authenticated,
|
|
busy,
|
|
error,
|
|
getToken,
|
|
login,
|
|
logout,
|
|
};
|
|
}
|