fix: Await logout
This commit is contained in:
@@ -45,7 +45,7 @@ function UserDelete() {
|
|||||||
async (data: FormData) => {
|
async (data: FormData) => {
|
||||||
try {
|
try {
|
||||||
await auth.deleteUser(data);
|
await auth.deleteUser(data);
|
||||||
auth.logout();
|
await auth.logout();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast(error.message, {
|
showToast(error.message, {
|
||||||
type: "error",
|
type: "error",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import User from "~/models/User";
|
|||||||
import env from "~/env";
|
import env from "~/env";
|
||||||
import { client } from "~/utils/ApiClient";
|
import { client } from "~/utils/ApiClient";
|
||||||
import Desktop from "~/utils/Desktop";
|
import Desktop from "~/utils/Desktop";
|
||||||
|
import Logger from "~/utils/Logger";
|
||||||
|
|
||||||
const AUTH_STORE = "AUTH_STORE";
|
const AUTH_STORE = "AUTH_STORE";
|
||||||
const NO_REDIRECT_PATHS = ["/", "/create", "/home", "/logout"];
|
const NO_REDIRECT_PATHS = ["/", "/create", "/home", "/logout"];
|
||||||
@@ -322,7 +323,7 @@ export default class AuthStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// invalidate authentication token on server
|
// invalidate authentication token on server
|
||||||
client.post(`/auth.delete`);
|
const promise = client.post(`/auth.delete`);
|
||||||
|
|
||||||
// remove authentication token itself
|
// remove authentication token itself
|
||||||
removeCookie("accessToken", {
|
removeCookie("accessToken", {
|
||||||
@@ -349,5 +350,11 @@ export default class AuthStore {
|
|||||||
// Tell the host application we logged out, if any – allows window cleanup.
|
// Tell the host application we logged out, if any – allows window cleanup.
|
||||||
Desktop.bridge?.onLogout?.();
|
Desktop.bridge?.onLogout?.();
|
||||||
this.rootStore.logout();
|
this.rootStore.logout();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await promise;
|
||||||
|
} catch (err) {
|
||||||
|
Logger.error("Failed to delete authentication", err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class ApiClient {
|
|||||||
|
|
||||||
// Handle 401, log out user
|
// Handle 401, log out user
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
stores.auth.logout();
|
await stores.auth.logout();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ class ApiClient {
|
|||||||
|
|
||||||
if (response.status === 403) {
|
if (response.status === 403) {
|
||||||
if (error.error === "user_suspended") {
|
if (error.error === "user_suspended") {
|
||||||
stores.auth.logout();
|
await stores.auth.logout();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user