Added cookie support
This commit is contained in:
10
js/api.js
10
js/api.js
@@ -1,11 +1,12 @@
|
||||
const prefix = document.getElementsByTagName("base")[0].href;
|
||||
const prefix = document.getElementsByTagName("base")[0].href.replace(/(?=.*)\/$/gm, "");
|
||||
async function unknownResponse(resp) {
|
||||
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})`);
|
||||
}
|
||||
}
|
||||
function buildQuery(options) {
|
||||
@@ -26,7 +27,8 @@ function buildQuery(options) {
|
||||
async function login(username, password) {
|
||||
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