2021-08-06 19:17:52 +05:30
|
|
|
import React, { useEffect } from 'react';
|
2021-08-04 12:18:57 +05:30
|
|
|
import { Switch, Route } from 'react-router-dom';
|
|
|
|
import { useAuthorizer } from '@authorizerdev/authorizer-react';
|
|
|
|
import Dashboard from './pages/dashboard';
|
|
|
|
import Login from './pages/login';
|
|
|
|
import ResetPassword from './pages/rest-password';
|
|
|
|
|
|
|
|
export default function Root() {
|
2021-08-06 19:17:52 +05:30
|
|
|
const { token, loading, config } = useAuthorizer();
|
2021-08-04 12:18:57 +05:30
|
|
|
|
2021-08-06 19:17:52 +05:30
|
|
|
useEffect(() => {
|
2021-08-09 08:46:07 +05:30
|
|
|
if (token) {
|
2021-10-04 03:17:50 +05:30
|
|
|
const url = new URL(config.redirectURL || '/app');
|
2021-08-09 08:46:07 +05:30
|
|
|
if (url.origin !== window.location.origin) {
|
2021-10-04 03:17:50 +05:30
|
|
|
window.location.href = config.redirectURL || '/app';
|
2021-08-09 08:46:07 +05:30
|
|
|
}
|
2021-08-06 19:17:52 +05:30
|
|
|
}
|
|
|
|
return () => {};
|
|
|
|
}, [token]);
|
2021-08-04 12:18:57 +05:30
|
|
|
|
2021-08-06 19:17:52 +05:30
|
|
|
if (loading) {
|
|
|
|
return <h1>Loading...</h1>;
|
|
|
|
}
|
2021-08-04 12:18:57 +05:30
|
|
|
|
2021-08-06 19:17:52 +05:30
|
|
|
if (token) {
|
|
|
|
return (
|
|
|
|
<Switch>
|
|
|
|
<Route path="/app" exact>
|
|
|
|
<Dashboard />
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Switch>
|
|
|
|
<Route path="/app" exact>
|
|
|
|
<Login />
|
|
|
|
</Route>
|
|
|
|
<Route path="/app/reset-password">
|
|
|
|
<ResetPassword />
|
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
);
|
2021-08-04 12:18:57 +05:30
|
|
|
}
|