Skip to content

Commit 725f499

Browse files
Merge pull request #710 from PierreBrisorgueil/fixSignout
fix(_app): signout & routes redirection if unAuthorized 🐛
2 parents 4443e4e + 5d502f0 commit 725f499

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/modules/_app/app.router.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import Vue from 'vue';
55
import Router from 'vue-router';
66
import store from '@/modules/_app/app.store';
7+
import config from '@/config';
78

89
import home from '@/modules/home/router/home.router';
910
import auth from '@/modules/auth/router/auth.router';
@@ -29,9 +30,12 @@ const router = new Router({
2930
router.beforeEach((to, from, next) => {
3031
// meta
3132
document.title = to.name;
33+
const userRoles = localStorage.getItem(`${config.cookie.prefix}UserRoles`)
34+
? localStorage.getItem(`${config.cookie.prefix}UserRoles`).split(',')
35+
: [];
3236
// secu
33-
if (to.matched.some((record) => record.meta.requiresAuth)) {
34-
if (store.getters.isLoggedIn) {
37+
if (to.matched.some((record) => record.meta.roles)) {
38+
if (store.getters.isLoggedIn && to.meta.roles.some((r) => userRoles.includes(r))) {
3539
next();
3640
return;
3741
}

src/modules/_core/components/core.header.component.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default {
169169
signout() {
170170
this.$store.dispatch('signout').then(() => {
171171
this.$store.dispatch('refreshNav');
172-
if (this.$route.path !== '/') this.$router.push('/home');
172+
if (this.$route.path !== '/') this.$router.push('/');
173173
});
174174
},
175175
},

src/modules/home/components/home.banner.component.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ export default {
120120
};
121121
},
122122
computed: {
123-
...mapGetters(['subscription']),
123+
...mapGetters(['homeSubscription']),
124124
email: {
125125
get() {
126-
return this.subscription.email;
126+
return this.homeSubscription.email;
127127
},
128128
set(email) {
129129
this.save = true;
@@ -136,9 +136,9 @@ export default {
136136
return `${this.config.home.temporalBackground}/${`0${new Date().getHours()}`.slice(-2)}.jpg`;
137137
},
138138
createSubscription() {
139-
if (this.rules.email(this.subscription.email)) {
139+
if (this.rules.email(this.homeSubscription.email)) {
140140
this.$store
141-
.dispatch('createSubscription', this.subscription)
141+
.dispatch('createSubscription', this.homeSubscription)
142142
.catch((err) => console.log(err));
143143
}
144144
},

src/modules/home/stores/home.store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const whitelists = ['email', 'news'];
1717
const getters = {
1818
contents: (state) => state.contents,
1919
news: (state) => state.news,
20-
subscription: (state) => state.subscription,
20+
homeSubscription: (state) => state.subscription,
2121
contact: (state) => state.contact,
2222
statistics: (state) => state.statistics,
2323
};

0 commit comments

Comments
 (0)