user header name added
This commit is contained in:
@@ -7,6 +7,7 @@ import Layout from '../layout/Layout'
|
||||
import siteLinks from '../../links/siteLinks'
|
||||
|
||||
import debounceFunction from '../../utils/debounceFunction'
|
||||
import { accountDashboard } from '../../services/services';
|
||||
|
||||
|
||||
export default function UserExist() {
|
||||
@@ -19,9 +20,9 @@ export default function UserExist() {
|
||||
|
||||
const [lastActivityTime, setLastActivityTime] = useState(Date.now()); // HOLDS THE INITIAL TIME USER LOGS IN
|
||||
|
||||
const { userDetails: { token }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active
|
||||
const { userDetails: { lastname }} = useSelector((state) => state?.userDetails); // CHECKS IF USER Details are avaliable, to determine if user is active
|
||||
|
||||
let loggedIn = token ? true : false; // variable to determine if user is logged in
|
||||
let loggedIn = lastname ? true : false; // variable to determine if user is logged in
|
||||
// console.log('loggedIn', loggedIn)
|
||||
|
||||
// Function to log the user out
|
||||
@@ -57,25 +58,40 @@ export default function UserExist() {
|
||||
})
|
||||
}
|
||||
},[lastActivityTime])
|
||||
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
let token = localStorage.getItem('token')
|
||||
const timer = setTimeout(()=>{
|
||||
if(token && loggedIn){
|
||||
setLoading(false)
|
||||
}else if(token && !loggedIn){
|
||||
const data = {token}
|
||||
dispatch(updateUserDetails({ ...data }));
|
||||
setLoading(false)
|
||||
// dispatch(updateUserDetails({ ...res.data }));
|
||||
}else{
|
||||
navigate('auth/login')
|
||||
}
|
||||
},1000)
|
||||
|
||||
return () => clearTimeout(timer)
|
||||
if(!token){
|
||||
return navigate(siteLinks.login)
|
||||
}
|
||||
|
||||
accountDashboard().then(res => {
|
||||
const {dash_data} = res?.data
|
||||
setLoading(false)
|
||||
dispatch(updateUserDetails({ ...dash_data }));
|
||||
}).catch(err => {
|
||||
navigate(siteLinks.login)
|
||||
})
|
||||
},[])
|
||||
|
||||
|
||||
// useEffect(()=>{
|
||||
// let token = localStorage.getItem('token')
|
||||
// const timer = setTimeout(()=>{
|
||||
// if(token && loggedIn){
|
||||
// setLoading(false)
|
||||
// }else if(token && !loggedIn){
|
||||
// const data = {token}
|
||||
// dispatch(updateUserDetails({ ...data }));
|
||||
// setLoading(false)
|
||||
// // dispatch(updateUserDetails({ ...res.data }));
|
||||
// }else{
|
||||
// navigate('auth/login')
|
||||
// }
|
||||
// },1000)
|
||||
|
||||
// return () => clearTimeout(timer)
|
||||
// },[])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user