More refactoring
This commit is contained in:
parent
4d0f36d475
commit
bfce343e7b
@ -33,7 +33,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
result.url,
|
result.url,
|
||||||
);
|
);
|
||||||
location.href = result.url;
|
location.href = result.url;
|
||||||
throw new Error("Invalid credentials");
|
throw new Error("Not authenticated");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@ -155,4 +155,10 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
|||||||
perm: (res.headers.get("X-Permission") as "rw" | "ro") || "rw",
|
perm: (res.headers.get("X-Permission") as "rw" | "ro") || "rw",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used to check if the server is reachable and the user is authenticated
|
||||||
|
// If not: throws an error or invokes a redirect
|
||||||
|
async ping() {
|
||||||
|
await this.authenticatedFetch(`${this.url}/SETTINGS.md`, { method: "GET" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ export class Client {
|
|||||||
|
|
||||||
this.focus();
|
this.focus();
|
||||||
|
|
||||||
// This constructor will always be followed by an invocatition of init()
|
// This constructor will always be followed by an (async) invocatition of init()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,17 +145,22 @@ export class Client {
|
|||||||
// Load settings
|
// Load settings
|
||||||
this.settings = await this.loadSettings();
|
this.settings = await this.loadSettings();
|
||||||
|
|
||||||
this.initNavigator();
|
|
||||||
|
|
||||||
// Pinging a remote space to ensure we're authenticated properly, if not will result in a redirect to auth page
|
// Pinging a remote space to ensure we're authenticated properly, if not will result in a redirect to auth page
|
||||||
try {
|
try {
|
||||||
await this.remoteSpacePrimitives.getFileMeta("SETTINGS");
|
await this.remoteSpacePrimitives.ping();
|
||||||
} catch {
|
} catch (e: any) {
|
||||||
|
if (e.message === "Not authenticated") {
|
||||||
|
console.warn("Not authenticated, redirecting to auth page");
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.warn(
|
console.warn(
|
||||||
"Could not reach remote server, either we're offline or not authenticated",
|
"Could not reach remote server, we're offline or the server is down",
|
||||||
|
e,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.initNavigator();
|
||||||
|
|
||||||
await this.reloadPlugs();
|
await this.reloadPlugs();
|
||||||
|
|
||||||
this.loadCustomStyles().catch(console.error);
|
this.loadCustomStyles().catch(console.error);
|
||||||
|
Loading…
Reference in New Issue
Block a user