Add public map with JWT admin login and protect admin APIs.
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>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user