diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 51770d8..ecbcf34 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -8,8 +8,9 @@ Publishers @@ -38,12 +39,20 @@ export default { router.push({ name: 'login' }) } - let user = auth.getUserInfos() - this.gravatar = 'https://www.gravatar.com/avatar/' + user.avatar + '?s=40' + // Set the users avatar + this.setAvatar() + }, + watch: { + // call again the method if the route changes + '$route': 'setAvatar' }, methods: { logout () { auth.logout() + }, + setAvatar () { + auth.getUserInfos() + this.gravatar = 'https://www.gravatar.com/avatar/' + this.user.infos.avatar + '?s=40&d=mm' } } } diff --git a/frontend/src/auth/index.js b/frontend/src/auth/index.js index 22ec5b1..0caa7a6 100644 --- a/frontend/src/auth/index.js +++ b/frontend/src/auth/index.js @@ -21,6 +21,7 @@ export default { // Tell others the user is autheticated this.user.authenticated = true + this.getUserInfos() // Hide the loader context.loading = false @@ -47,9 +48,10 @@ export default { checkAuth () { let jwt = localStorage.getItem('token') + this.getUserInfos() this.user.authenticated = false if (jwt) { - let infos = this.getUserInfos() + let infos = this.user.infos let ts = Math.round((new Date()).getTime() / 1000) if (infos.exp >= ts) { this.user.authenticated = true @@ -60,6 +62,7 @@ export default { getUserInfos () { let jwt = localStorage.getItem('token') if (jwt) { + this.user.infos = this.parseJwt(localStorage.getItem('token')) return this.parseJwt(localStorage.getItem('token')) } else { return {} diff --git a/frontend/src/components/Login.vue b/frontend/src/components/Login.vue index 478bdbc..eec83a8 100644 --- a/frontend/src/components/Login.vue +++ b/frontend/src/components/Login.vue @@ -11,13 +11,13 @@
- +
- +
Login
@@ -78,6 +78,7 @@