Added cookie support
This commit is contained in:
10
js/api.ts
10
js/api.ts
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user