diff --git a/client/package.json b/client/package.json index 0789fa67c..425d6826a 100644 --- a/client/package.json +++ b/client/package.json @@ -75,6 +75,7 @@ "classnames": "^2.2.6", "graphql": "^14.0.2", "graphql-tag": "^2.10.0", + "jwt-decode": "^2.2.0", "mini-css-extract-plugin": "^0.4.4", "npm": "^6.4.1", "optimize-css-assets-webpack-plugin": "^5.0.1", diff --git a/client/src/views/header/index.js b/client/src/views/header/index.js index 2f46a9dea..59fff5b7f 100644 --- a/client/src/views/header/index.js +++ b/client/src/views/header/index.js @@ -1,5 +1,6 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' +import jwtDecode from 'jwt-decode' import { withStyles } from '@material-ui/core/styles' import AppBar from '@material-ui/core/AppBar' @@ -81,7 +82,12 @@ class Header extends Component { render () { let { classes, auth } = this.props - + if (window.localStorage.getItem('access_token')) { + if (jwtDecode(window.localStorage.getItem('access_token')).exp < new Date().getTime() / 1000) { + window.localStorage.clear() + window.location.reload() + } + } let user = JSON.parse(this.state.user) return (