[ReviewDB] update for new api changes; some fixes (#2120)

Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
Manti 2024-01-22 03:18:48 +03:00 committed by GitHub
parent 1670733458
commit e707538b73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 126 additions and 84 deletions

View file

@ -61,14 +61,17 @@ export function authorize(callback?: any) {
const res = await fetch(url, {
headers: new Headers({ Accept: "application/json" })
});
const { token, success } = await res.json();
if (success) {
updateAuth({ token });
showToast("Successfully logged in!", Toasts.Type.SUCCESS);
callback?.();
} else if (res.status === 1) {
showToast("An Error occurred while logging in.", Toasts.Type.FAILURE);
if (!res.ok) {
const { message } = await res.json();
showToast(message || "An error occured while authorizing", Toasts.Type.FAILURE);
return;
}
const { token } = await res.json();
updateAuth({ token });
showToast("Successfully logged in!", Toasts.Type.SUCCESS);
callback?.();
} catch (e) {
new Logger("ReviewDB").error("Failed to authorize", e);
}