feat: consistent authentication flow

fix: missing suspense on login
feat: re-prompt MFA if fail on login
This commit is contained in:
Paul Makles
2022-06-29 16:27:57 +01:00
parent 0261fec676
commit 1fcb3cedc1
5 changed files with 57 additions and 37 deletions

View File

@@ -1,6 +1,8 @@
import { observer } from "mobx-react-lite";
import { Redirect } from "react-router-dom";
import { Preloader } from "@revoltchat/ui";
import { clientController } from "../../controllers/client/ClientController";
interface Props {
@@ -10,6 +12,10 @@ interface Props {
children: Children;
}
/**
* Check that we are logged in or out and redirect accordingly.
* Also prevent render until the client is ready to display.
*/
export const CheckAuth = observer((props: Props) => {
const loggedIn = clientController.isLoggedIn();
@@ -22,5 +28,14 @@ export const CheckAuth = observer((props: Props) => {
return <Redirect to="/" />;
}
// Block render if client is getting ready to work.
if (
props.auth &&
clientController.isLoggedIn() &&
!clientController.isReady()
) {
return <Preloader type="spinner" />;
}
return <>{props.children}</>;
});