mirror of
https://gitlab.com/comunic/comunicconsole
synced 2025-06-20 00:25:19 +00:00
Can login using access reset token
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user