mirror of
https://github.com/Telecominfraproject/wlan-cloud-ui.git
synced 2025-11-02 19:57:58 +00:00
set up Authentication
This commit is contained in:
32
app/containers/App/components/ProtectedRouteWithLayout.js
Normal file
32
app/containers/App/components/ProtectedRouteWithLayout.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import T from 'prop-types';
|
||||
import { Route, Redirect } from 'react-router-dom';
|
||||
|
||||
import MasterLayout from 'containers/MasterLayout';
|
||||
import { getItem } from 'utils/localStorage';
|
||||
import { AUTH_TOKEN } from 'constants/index';
|
||||
|
||||
const ProtectedRouteWithLayout = ({ component: Component, ...rest }) => (
|
||||
<Route
|
||||
{...rest}
|
||||
render={props =>
|
||||
getItem(AUTH_TOKEN) ? (
|
||||
<MasterLayout>
|
||||
<Component {...props} />
|
||||
</MasterLayout>
|
||||
) : (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: '/login',
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
ProtectedRouteWithLayout.propTypes = {
|
||||
component: T.func.isRequired,
|
||||
};
|
||||
|
||||
export default ProtectedRouteWithLayout;
|
||||
Reference in New Issue
Block a user