Feat/login
This commit is contained in:
parent
4803c4d8b6
commit
3361d4c043
7 changed files with 91 additions and 167 deletions
18
src/App.tsx
18
src/App.tsx
|
|
@ -1,28 +1,29 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { useMatch, Router, navigate, RouteComponentProps, Redirect } from '@reach/router';
|
||||
import { Router, RouteComponentProps } from '@reach/router';
|
||||
import { Toaster } from 'react-hot-toast';
|
||||
|
||||
import { isValid } from 'src/services/api';
|
||||
import { useAuth } from 'src/services/auth';
|
||||
import { Apps, Dashboard, Users, Login, AppSingle } from './modules';
|
||||
import { Layout } from './components';
|
||||
import { LoginCallback } from './modules/login/LoginCallback';
|
||||
|
||||
type AppProps = RouteComponentProps;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function App(_: AppProps) {
|
||||
const { auth } = useAuth();
|
||||
const isLoginPage = useMatch('/login');
|
||||
// const isLoginPage = useMatch('/login');
|
||||
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
const [initializedToken, setInitializedToken] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isValid(auth) && !isLoginPage) {
|
||||
navigate('/login');
|
||||
}
|
||||
}, [auth, isLoginPage]);
|
||||
// useEffect(() => {
|
||||
// if (!isValid(auth) && !isLoginPage) {
|
||||
// navigate('/login');
|
||||
// }
|
||||
// }, [auth, isLoginPage]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isValid(auth) && (!initialized || initializedToken !== auth.token)) {
|
||||
|
|
@ -48,6 +49,7 @@ function App(_: AppProps) {
|
|||
{!isValid(auth) ? (
|
||||
<Router>
|
||||
<Login path="/login" />
|
||||
<LoginCallback path="/login-callback" />
|
||||
</Router>
|
||||
) : (
|
||||
<Layout>
|
||||
|
|
@ -60,7 +62,7 @@ function App(_: AppProps) {
|
|||
</Layout>
|
||||
)}
|
||||
|
||||
{isValid(auth) ? <Redirect from="/" to="/dashboard" noThrow /> : <Redirect from="/" to="/login" noThrow />}
|
||||
{/* {isValid(auth) ? <Redirect from="/" to="/dashboard" noThrow /> : <Redirect from="/" to="/" noThrow />} */}
|
||||
|
||||
{/* Place to load notifications */}
|
||||
<div
|
||||
|
|
|
|||
Reference in a new issue