Skip to content

Commit cf49209

Browse files
committed
Fixing expiration token
1 parent f46d998 commit cf49209

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/router.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ const isEmpty = obj => !obj || Object.keys(obj).length === 0;
290290
const enableLogger = process.env.NODE_ENV !== 'production';
291291

292292
router.beforeEach(async (to, from, next) => {
293+
// Check if token is expired
294+
if (store.state.userToken) {
295+
const today = new Date()
296+
const expirationDate = new Date(store.state.userToken.expiration * 1000)
297+
if (today > expirationDate) {
298+
console.info('- user token is expired!')
299+
store.commit('logout')
300+
next({ name: 'login', query: { redirect: to.path } });
301+
}
302+
}
293303
// next();
294304
// if (to.meta.withNavbar) document.documentElement.classList.add('has-navbar-fixed-top');
295305
// else document.documentElement.classList.remove('has-navbar-fixed-top');

0 commit comments

Comments
 (0)