Can login using access reset token

This commit is contained in:
2021-05-12 17:05:46 +02:00
parent b1929fc21f
commit 05117e71a3
3 changed files with 168 additions and 26 deletions

View File

@ -25,12 +25,13 @@ export async function serverRequest(uri: string, args?: any): Promise<any> {
// TODO : add access token, once supported
const result = await (
await fetch((await ConfigHelper.apiURL()) + uri, {
method: "POST",
body: fd,
})
).json();
const result = await fetch((await ConfigHelper.apiURL()) + uri, {
method: "POST",
body: fd,
});
return result;
if (result.status !== 200)
throw new Error("Request failed with status " + result.status);
return await result.json();
}

View File

@ -10,6 +10,8 @@ export interface AuthOptions {
reset_token: string;
}
const SESSION_STORAGE_TOKEN = "auth_token";
export class AccountHelper {
/**
* Check whether access token are available
@ -30,4 +32,19 @@ export class AccountHelper {
mail: mail,
});
}
/**
* Attempt to authenticate user using a reset token
*
* @param mail Email address of the admin
* @param token The reset token
*/
static async authWithResetToken(mail: string, token: string) {
const res = await serverRequest("accounts/auth_with_reset_token", {
mail: mail,
token: token,
});
sessionStorage.setItem(SESSION_STORAGE_TOKEN, res.token);
}
}