user role added
This commit is contained in:
parent
ad0a06d593
commit
70ed1e2a65
@ -22,6 +22,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
|
||||
*/
|
||||
export const getHomeRouteForLoggedInUser = userRole => {
|
||||
if (userRole === 'admin') return '/'
|
||||
if (userRole === 'client') return { name: 'access-control' }
|
||||
if (userRole === 'client') return '/'
|
||||
return { name: 'auth-login' }
|
||||
}
|
||||
|
@ -11,10 +11,6 @@ const Footer = () => {
|
||||
</a>
|
||||
<span className='d-none d-sm-inline-block'>, All rights Reserved</span>
|
||||
</span>
|
||||
<span className='float-md-right d-none d-md-block'>
|
||||
Hand-crafted & Made with
|
||||
<Heart size={14} />
|
||||
</span>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ** React Imports
|
||||
import { useState } from 'react'
|
||||
import React, { useState, useEffect, lazy } from 'react'
|
||||
|
||||
// ** Horizontal Menu Array
|
||||
import navigation from '@src/navigation/horizontal'
|
||||
|
@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
|
||||
import Avatar from '@components/avatar'
|
||||
|
||||
// ** Utils
|
||||
import { isUserLoggedIn } from '@utils'
|
||||
import { isUserLoggedIn, getUserData } from '@utils'
|
||||
|
||||
// ** Store & Actions
|
||||
import { useDispatch } from 'react-redux'
|
||||
@ -50,11 +50,12 @@ const UserDropdown = () => {
|
||||
<User size={14} className='mr-75' />
|
||||
<span className='align-middle'>Profile</span>
|
||||
</DropdownItem>
|
||||
{getUserData.role === "admin" &&
|
||||
<DropdownItem tag={Link} to='/apps/todo'>
|
||||
<CheckSquare size={14} className='mr-75' />
|
||||
<span className='align-middle'>Tasks</span>
|
||||
</DropdownItem>
|
||||
|
||||
}
|
||||
<DropdownItem divider />
|
||||
<DropdownItem tag={Link} to='/pages/account-settings'>
|
||||
<Settings size={14} className='mr-75' />
|
||||
|
@ -1,4 +1,5 @@
|
||||
import useJwt from '@src/@core/auth/jwt/useJwt'
|
||||
import { DefaultRoute } from '../router/routes'
|
||||
|
||||
/**
|
||||
* Return if user is logged in
|
||||
@ -10,6 +11,13 @@ export const isUserLoggedIn = () => {
|
||||
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName)
|
||||
}
|
||||
|
||||
export const getDefaultRoute = () => {
|
||||
const userdata = JSON.parse(localStorage.getItem("userData"))
|
||||
const userrole = userdata === null ? '' : userdata.role
|
||||
const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
|
||||
return redirect
|
||||
}
|
||||
|
||||
export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
|
||||
|
||||
/**
|
||||
@ -22,6 +30,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
|
||||
*/
|
||||
export const getHomeRouteForLoggedInUser = userRole => {
|
||||
if (userRole === 'admin') return '/'
|
||||
if (userRole === 'client') return { name: 'access-control' }
|
||||
if (userRole === 'client') return '/'
|
||||
return { name: 'auth-login' }
|
||||
}
|
||||
|
10
src/navigation/horizontal/clientHome.js
Normal file
10
src/navigation/horizontal/clientHome.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { Home, Activity, ShoppingCart } from 'react-feather'
|
||||
|
||||
export default [
|
||||
{
|
||||
id: 'client',
|
||||
title: 'Dashboard',
|
||||
icon: <Home />,
|
||||
navLink: '/client'
|
||||
}
|
||||
]
|
@ -1,7 +1,14 @@
|
||||
// ** Navigation sections imports
|
||||
import apps from './apps'
|
||||
import dashboards from './dashboards'
|
||||
import clientHome from './clientHome'
|
||||
|
||||
const userdata = JSON.parse(localStorage.getItem("userData"))
|
||||
const userrole = userdata === null ? '' : userdata.role
|
||||
|
||||
// ** Merge & Export
|
||||
export default [...dashboards, ...apps]
|
||||
const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...clientHome] : [])
|
||||
console.log(userrole)
|
||||
console.log(navarr)
|
||||
export default navarr
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
// ** Navigation sections imports
|
||||
import apps from './apps'
|
||||
|
||||
import dashboards from './dashboards'
|
||||
|
||||
|
||||
const userdata = JSON.parse(localStorage.getItem("userData"))
|
||||
const userrole = userdata === null ? '' : userdata.role
|
||||
// ** Merge & Export
|
||||
export default [...dashboards, ...apps]
|
||||
const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...dashboards] : [])
|
||||
export default navarr
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { Suspense, useContext, lazy } from 'react'
|
||||
|
||||
// ** Utils
|
||||
import { isUserLoggedIn } from '@utils'
|
||||
import { isUserLoggedIn, getDefaultRoute } from '@utils'
|
||||
import { useLayout } from '@hooks/useLayout'
|
||||
import { AbilityContext } from '@src/utility/context/Can'
|
||||
import { useRouterTransition } from '@hooks/useRouterTransition'
|
||||
@ -85,11 +85,9 @@ const Router = () => {
|
||||
** If user is not Logged in & route.meta.authRoute, !route.meta.publicRoute are undefined
|
||||
** Then redirect user to login
|
||||
*/
|
||||
|
||||
return <Redirect to='/login' />
|
||||
} else if (route.meta && route.meta.authRoute && isUserLoggedIn()) {
|
||||
// ** If route has meta and authRole and user is Logged in then redirect user to home page (DefaultRoute)
|
||||
|
||||
return <Redirect to='/' />
|
||||
// } else if (isUserLoggedIn() && !ability.can(action || 'read', resource)) {
|
||||
// // ** If user is Logged in and doesn't have ability to visit the page redirect the user to Not Authorized
|
||||
@ -197,7 +195,7 @@ const Router = () => {
|
||||
exact
|
||||
path='/'
|
||||
render={() => {
|
||||
return isUserLoggedIn() ? <Redirect to={DefaultRoute} /> : <Redirect to='/login' />
|
||||
return isUserLoggedIn() ? <Redirect to={getDefaultRoute()} /> : <Redirect to='/login' />
|
||||
}}
|
||||
/>
|
||||
{/* Not Auth Route */}
|
||||
|
@ -130,6 +130,11 @@ const PagesRoutes = [
|
||||
meta: {
|
||||
navLink: '/account/view'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/client',
|
||||
exact: true,
|
||||
component: lazy(() => import('../../views/apps/client/dashboard'))
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { DefaultRoute } from '../router/routes'
|
||||
// ** Checks if an object is empty (returns boolean)
|
||||
export const isObjEmpty = obj => Object.keys(obj).length === 0
|
||||
|
||||
@ -50,6 +51,12 @@ export const formatDateToMonthShort = (value, toTimeForCurrentDay = true) => {
|
||||
*/
|
||||
export const isUserLoggedIn = () => localStorage.getItem('userData')
|
||||
export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
|
||||
export const getDefaultRoute = () => {
|
||||
const userdata = JSON.parse(localStorage.getItem("userData"))
|
||||
const userrole = userdata === null ? '' : userdata.role
|
||||
const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
|
||||
return redirect
|
||||
}
|
||||
|
||||
/**
|
||||
** This function is used for demo purpose route navigation
|
||||
@ -61,7 +68,7 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
|
||||
*/
|
||||
export const getHomeRouteForLoggedInUser = userRole => {
|
||||
if (userRole === 'admin') return '/'
|
||||
if (userRole === 'client') return '/access-control'
|
||||
if (userRole === 'client') return '/'
|
||||
return '/login'
|
||||
}
|
||||
|
||||
|
12
src/views/apps/client/dashboard/index.js
Normal file
12
src/views/apps/client/dashboard/index.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { Fragment } from "react"
|
||||
|
||||
|
||||
const clientDashboard = () => {
|
||||
return (
|
||||
<Fragment>
|
||||
<h3>CLIENT DASHBOARD</h3>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
export default clientDashboard
|
@ -53,6 +53,7 @@ const TODO = () => {
|
||||
)
|
||||
}, [store.tasks.length, paramsURL.filter, paramsURL.tag, query, sort])
|
||||
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Sidebar
|
||||
|
@ -85,7 +85,6 @@ const Login = props => {
|
||||
</Col>
|
||||
<Col className='d-flex align-items-center auth-bg px-2 p-lg-5' lg='4' sm='12'>
|
||||
<Col className='px-xl-2 mx-auto' sm='8' md='6' lg='12'>
|
||||
|
||||
<CardText className='mb-2'>Please sign-in to your account and start the adventure</CardText>
|
||||
<Alert color='primary'>
|
||||
<div className='alert-body font-small-2'>
|
||||
|
Loading…
x
Reference in New Issue
Block a user