- initial;
This commit is contained in:
28
src/components/ProtectedRoute/index.js
Normal file
28
src/components/ProtectedRoute/index.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
import { Navigate, Outlet } from 'react-router-dom';
|
||||
|
||||
// tools
|
||||
import AuthenticationService from '../../service/authentication-service';
|
||||
|
||||
const ProtectedRoute = () => {
|
||||
|
||||
if (!AuthenticationService.wasLoggedIn()) {
|
||||
return (<Navigate to={'/login'} replace/>);
|
||||
}
|
||||
|
||||
if (AuthenticationService.isExpired()) {
|
||||
return (<Navigate to={'/login?redirectReason=expired'} replace/>);
|
||||
}
|
||||
|
||||
if (!AuthenticationService.isLoggedIn()) {
|
||||
return (<Navigate to={'/login?redirectReason=auth_required'} replace/>);
|
||||
}
|
||||
|
||||
if (window.location.pathname === '/') {
|
||||
return (<Navigate to={'/pages/dashboard'} replace/>);
|
||||
}
|
||||
|
||||
return <Outlet/>;
|
||||
}
|
||||
|
||||
export default ProtectedRoute;
|
||||
Reference in New Issue
Block a user