|
@@ -27,6 +27,7 @@ import Footer from "../Components/Footer";
|
27
|
27
|
|
28
|
28
|
import { Drawer as MuiDrawer, AppBar as MuiAppBar } from "../Components/Navigation/AppBar"
|
29
|
29
|
import { UserListItems, SecondaryListItems } from '../Components/Navigation/listItems';
|
|
30
|
+import jwtDecode from 'jwt-decode';
|
30
|
31
|
// import ProfilePicture from '../Images/man.png';
|
31
|
32
|
|
32
|
33
|
const drawerWidth = 240;
|
|
@@ -86,8 +87,8 @@ export function User() {
|
86
|
87
|
const navigate = useNavigate()
|
87
|
88
|
let dispatch = useDispatch()
|
88
|
89
|
let profile = useSelector((state) => state.user.profile)
|
89
|
|
- let name = `${(profile?.email.substring(0, 1))} ${profile?.email.substring(1, 2)}`
|
90
|
|
-
|
|
90
|
+ const auth = useSelector((state) => state.token.candi)
|
|
91
|
+ let name = profile ? `${(profile?.email.substring(0, 1))} ${profile?.email.substring(1, 2)}` : ""
|
91
|
92
|
const CerrarSession = () => {
|
92
|
93
|
dispatch(removeToken({ candi: true }))
|
93
|
94
|
navigate('/logincd')
|
|
@@ -105,7 +106,27 @@ export function User() {
|
105
|
106
|
}
|
106
|
107
|
}
|
107
|
108
|
const [anchorElMovil, setAnchorElMov] = React.useState(false);
|
108
|
|
- React.useEffect(() => isMovil ? setOpen(false) : null, [isMovil])
|
|
109
|
+ React.useEffect(() => {
|
|
110
|
+
|
|
111
|
+ const { exp } = jwtDecode(auth.token)
|
|
112
|
+ let timestamp = exp * 1000;
|
|
113
|
+ let exp_in = timestamp - Date.now();
|
|
114
|
+ console.log("EXP IN : ", exp_in)
|
|
115
|
+ if(exp_in <= 0 ){
|
|
116
|
+ alert("TOKEN EXPIRADO, PORFAVOR INICIA SESSION")
|
|
117
|
+ dispatch(removeToken({ candi: true}))
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ setTimeout(() => {
|
|
121
|
+ alert("TOKEN EXPIRADO, PORFAVOR INICIA SESSION")
|
|
122
|
+
|
|
123
|
+ }, exp_in)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+ if(isMovil){
|
|
127
|
+ setOpen(false)
|
|
128
|
+ }
|
|
129
|
+ }, [isMovil, auth, dispatch])
|
109
|
130
|
|
110
|
131
|
return (
|
111
|
132
|
<ThemeProvider theme={mdTheme}>
|