Replace unauthorized status with a redirect
This commit is contained in:
parent
5ff9a5692b
commit
f39ab26cea
@ -21,13 +21,13 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
options.headers = { ...options.headers, ...{ "X-Sync-Mode": "true" } };
|
||||
}
|
||||
|
||||
const result = await fetch(url, { ...options });
|
||||
if (
|
||||
this.getRealStatus(result) === 401
|
||||
) {
|
||||
// Invalid credentials, reloading the browser should trigger authentication
|
||||
console.log("Going to redirect after", url);
|
||||
location.href = "/.auth?refer=" + location.pathname;
|
||||
const result = await fetch(url, {
|
||||
...options,
|
||||
});
|
||||
if (result.redirected) {
|
||||
// Got a redirect, we'll assume this is due to invalid credentials and redirecting to an auth page
|
||||
console.log("Got a redirect via the API so will redirect to URL", url);
|
||||
location.href = result.url;
|
||||
throw new Error("Invalid credentials");
|
||||
}
|
||||
return result;
|
||||
|
@ -218,8 +218,7 @@ export class HttpServer {
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
response.status = 401;
|
||||
response.body = "Unauthorized";
|
||||
response.redirect("/.auth");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -232,8 +231,7 @@ export class HttpServer {
|
||||
if (!excludedPaths.includes(request.url.pathname)) {
|
||||
const authCookie = await cookies.get("auth");
|
||||
if (!authCookie) {
|
||||
response.status = 401;
|
||||
response.body = "Unauthorized, please authenticate";
|
||||
response.redirect("/.auth");
|
||||
return;
|
||||
}
|
||||
const [username, hashedPassword] = authCookie.split(":");
|
||||
@ -243,8 +241,7 @@ export class HttpServer {
|
||||
hashedPassword,
|
||||
)
|
||||
) {
|
||||
response.status = 401;
|
||||
response.body = "Invalid username/password, please reauthenticate";
|
||||
response.redirect("/.auth");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user