Skip to content

Commit

Permalink
fix: jwt가 만료되었으면 로그인되지 않은 것으로 간주
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Dec 8, 2021
1 parent 912d839 commit 278977b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Login from '@/features/login/Login.vue';
import EventBus from '@/event-bus';
import services from '../../services';
import VueRouter from 'vue-router';
import {isFuture} from 'date-fns';
import {getCookie} from '@/utils/cookie';
import JWT, {JwtPayload} from 'jsonwebtoken';

Vue.use(VueRouter);

Expand Down Expand Up @@ -51,7 +54,20 @@ function routeRequiresAuth(route) {
}

function isLoggedIn() {
return document.cookie.includes('cafeteria-console-server-token');
const jwt = getCookie('cafeteria-console-server-token');

if (jwt == null) {
return false;
}

const decoded = JWT.decode(jwt) as JwtPayload;
const expiration = decoded.exp;

if (expiration == null) {
return true;
}

return isFuture(expiration * 1000);
}

const router = createRouter();
Expand Down

0 comments on commit 278977b

Please sign in to comment.