Account API endpoint fixes
This commit is contained in:
parent
f79348817f
commit
7ca9afad57
7 changed files with 15 additions and 13 deletions
|
@ -45,12 +45,12 @@ class AccountApi {
|
|||
return json.token;
|
||||
}
|
||||
|
||||
async logout(token) {
|
||||
async logout() {
|
||||
const url = accountTokenUrl(config.baseUrl);
|
||||
console.log(`[AccountApi] Logging out from ${url} using token ${token}`);
|
||||
console.log(`[AccountApi] Logging out from ${url} using token ${session.token()}`);
|
||||
const response = await fetch(url, {
|
||||
method: "DELETE",
|
||||
headers: withBearerAuth({}, token)
|
||||
headers: withBearerAuth({}, session.token())
|
||||
});
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
throw new UnauthorizedError();
|
||||
|
|
|
@ -57,7 +57,7 @@ const Stats = () => {
|
|||
const { t } = useTranslation();
|
||||
const { account } = useOutletContext();
|
||||
if (!account) {
|
||||
return <></>; // TODO loading
|
||||
return <></>;
|
||||
}
|
||||
const accountType = account.plan.code ?? "none";
|
||||
const normalize = (value, max) => (value / max * 100);
|
||||
|
@ -234,9 +234,9 @@ const DeleteAccount = () => {
|
|||
const handleDialogSubmit = async (newPassword) => {
|
||||
try {
|
||||
await accountApi.delete();
|
||||
await db.delete();
|
||||
setDialogOpen(false);
|
||||
console.debug(`[Account] Account deleted`);
|
||||
// TODO delete local storage
|
||||
session.resetAndRedirect(routes.app);
|
||||
} catch (e) {
|
||||
console.log(`[Account] Error deleting account`, e);
|
||||
|
|
|
@ -8,6 +8,7 @@ import * as React from "react";
|
|||
import {useEffect, useRef, useState} from "react";
|
||||
import Box from "@mui/material/Box";
|
||||
import {formatShortDateTime, shuffle, topicDisplayName} from "../app/utils";
|
||||
import db from "../app/db";
|
||||
import {useLocation, useNavigate} from "react-router-dom";
|
||||
import ClickAwayListener from '@mui/material/ClickAwayListener';
|
||||
import Grow from '@mui/material/Grow';
|
||||
|
@ -270,6 +271,7 @@ const ProfileIcon = (props) => {
|
|||
const handleLogout = async () => {
|
||||
try {
|
||||
await accountApi.logout();
|
||||
await db.delete();
|
||||
} finally {
|
||||
session.resetAndRedirect(routes.app);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue