|
|
@@ -27,6 +27,7 @@ import Footer from "../Components/Footer";
|
|
|
|
|
|
import { Drawer as MuiDrawer, AppBar as MuiAppBar } from "../Components/Navigation/AppBar"
|
|
|
import { UserListItems, SecondaryListItems } from '../Components/Navigation/listItems';
|
|
|
+import jwtDecode from 'jwt-decode';
|
|
|
// import ProfilePicture from '../Images/man.png';
|
|
|
|
|
|
const drawerWidth = 240;
|
|
|
@@ -86,8 +87,8 @@ export function User() {
|
|
|
const navigate = useNavigate()
|
|
|
let dispatch = useDispatch()
|
|
|
let profile = useSelector((state) => state.user.profile)
|
|
|
- let name = `${(profile?.email.substring(0, 1))} ${profile?.email.substring(1, 2)}`
|
|
|
-
|
|
|
+ const auth = useSelector((state) => state.token.candi)
|
|
|
+ let name = profile ? `${(profile?.email.substring(0, 1))} ${profile?.email.substring(1, 2)}` : ""
|
|
|
const CerrarSession = () => {
|
|
|
dispatch(removeToken({ candi: true }))
|
|
|
navigate('/logincd')
|
|
|
@@ -105,7 +106,27 @@ export function User() {
|
|
|
}
|
|
|
}
|
|
|
const [anchorElMovil, setAnchorElMov] = React.useState(false);
|
|
|
- React.useEffect(() => isMovil ? setOpen(false) : null, [isMovil])
|
|
|
+ React.useEffect(() => {
|
|
|
+
|
|
|
+ const { exp } = jwtDecode(auth.token)
|
|
|
+ let timestamp = exp * 1000;
|
|
|
+ let exp_in = timestamp - Date.now();
|
|
|
+ console.log("EXP IN : ", exp_in)
|
|
|
+ if(exp_in <= 0 ){
|
|
|
+ alert("TOKEN EXPIRADO, PORFAVOR INICIA SESSION")
|
|
|
+ dispatch(removeToken({ candi: true}))
|
|
|
+ }
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ alert("TOKEN EXPIRADO, PORFAVOR INICIA SESSION")
|
|
|
+
|
|
|
+ }, exp_in)
|
|
|
+
|
|
|
+
|
|
|
+ if(isMovil){
|
|
|
+ setOpen(false)
|
|
|
+ }
|
|
|
+ }, [isMovil, auth, dispatch])
|
|
|
|
|
|
return (
|
|
|
<ThemeProvider theme={mdTheme}>
|