fix: login btn does not work for readonly annoymous
parent
f8a7873582
commit
0a8b66aee3
|
@ -534,7 +534,7 @@ async function setupAuth() {
|
|||
$loginBtn.classList.remove("hidden");
|
||||
$loginBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
await checkAuth();
|
||||
await checkAuth("login");
|
||||
} catch { }
|
||||
location.reload();
|
||||
});
|
||||
|
@ -782,9 +782,10 @@ async function saveChange() {
|
|||
}
|
||||
}
|
||||
|
||||
async function checkAuth() {
|
||||
async function checkAuth(variant) {
|
||||
if (!DATA.auth) return;
|
||||
const res = await fetch(baseUrl(), {
|
||||
const qs = variant ? `?${variant}` : "";
|
||||
const res = await fetch(baseUrl() + qs, {
|
||||
method: "CHECKAUTH",
|
||||
});
|
||||
await assertResOK(res);
|
||||
|
|
|
@ -211,7 +211,18 @@ impl Server {
|
|||
}
|
||||
|
||||
if method.as_str() == "CHECKAUTH" {
|
||||
*res.body_mut() = body_full(user.clone().unwrap_or_default());
|
||||
match user.clone() {
|
||||
Some(user) => {
|
||||
*res.body_mut() = body_full(user);
|
||||
}
|
||||
None => {
|
||||
if has_query_flag(&query_params, "login") || !access_paths.perm().readwrite() {
|
||||
self.auth_reject(&mut res)?
|
||||
} else {
|
||||
*res.body_mut() = body_full("");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Ok(res);
|
||||
} else if method.as_str() == "LOGOUT" {
|
||||
self.auth_reject(&mut res)?;
|
||||
|
|
Loading…
Reference in New Issue