Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
added fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfthefirefox committed Aug 15, 2023
1 parent 1204b51 commit af26e39
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
18 changes: 15 additions & 3 deletions ui-dashboard/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ const App: React.FC = () => {
posthog?.reset(true);
}

navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
}
}
};
Expand All @@ -127,7 +131,11 @@ const App: React.FC = () => {
posthog?.reset(true);
}

navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
}
}
};
Expand Down Expand Up @@ -210,7 +218,11 @@ const App: React.FC = () => {
}

await authProvider.logout();
navigate("/login");
navigate("/login", {
state: {
isNeedLogout: true
}
});
};

const userMenu: MenuProps["items"] = [
Expand Down
24 changes: 22 additions & 2 deletions ui-dashboard/src/pages/login-page/login-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import "./login-page.scss";

import * as React from "react";
import {useNavigate} from "react-router-dom";
import {AxiosError} from "axios";
import {useNavigate, useLocation} from "react-router-dom";
import {Modal, Button, Typography, Form, Input, notification} from "antd";
import {GoogleOutlined, CheckOutlined} from "@ant-design/icons";
import logoImg from "/fav/android-chrome-192x192.png";
Expand All @@ -15,12 +16,17 @@ import SpinWithMask from "src/components/spin-with-mask/spin-with-mask";

const b = bevis("login-page");

interface LoginState {
isNeedLogout: boolean;
}

const LoginPage: React.FC = () => {
const [form] = Form.useForm<UserCreateForm>();
const [api, contextHolder] = notification.useNotification();
const [isFormSubmitting, setIsFormSubmitting] = React.useState<boolean>(false);
const [providersList, setProvidersList] = React.useState<AuthProvider[]>([]);
const navigate = useNavigate();
const state: LoginState = useLocation().state;

const openNotification = (title: string, description: string) => {
api.info({
Expand Down Expand Up @@ -60,7 +66,21 @@ const LoginPage: React.FC = () => {

useMount(async () => {
window.addEventListener("popstate", () => navigate("/login", {replace: true}));
localStorage.remove("merchantId");

if (state?.isNeedLogout) {
localStorage.remove("merchantId");
} else {
try {
await authProvider.getCookie();
await authProvider.getMe();
navigate("/");
} catch (e) {
if (e instanceof AxiosError && e.response?.status === 401) {
localStorage.remove("merchantId");
}
}
}

const availProviders = await authProvider.getProviders();
setProvidersList(availProviders ?? []);
});
Expand Down

0 comments on commit af26e39

Please sign in to comment.