Added cookie support

This commit is contained in:
2022-01-31 12:46:41 +01:00
parent 320c215492
commit f6362442ed
3 changed files with 13 additions and 9 deletions

View File

@@ -1,12 +1,13 @@
const prefix = document.getElementsByTagName("base")[0].href;
const prefix = document.getElementsByTagName("base")[0].href.replace(/(?=.*)\/$/gm, "");
async function unknownResponse(resp: Response): Promise<Error> {
let json = await resp.json()
let text = await resp.text()
try {
let json = JSON.parse(text)
return new Error(`${json["message"]} (${resp.status})`)
} catch (error) {
return new Error(`Server sent unknown error: ${await resp.text()} (${resp.status})`)
return new Error(`Server sent unknown error: ${text} (${resp.status})`)
}
}
@@ -52,7 +53,8 @@ interface Asset {
async function login(username: string, password: string): Promise<void> {
let result = await fetch(`${prefix}/api/login`, {
method: "POST",
body: JSON.stringify({"username": username, "password": password})
body: JSON.stringify({"username": username, "password": password}),
credentials: "include"
})
switch (result.status) {
case 200: