Files
shipping-portal/resources/assets/vue/general/mixins/guards.js
T
2023-09-21 00:19:21 +08:00

25 lines
1.3 KiB
JavaScript
Vendored

export default {
methods: {
routesGuard(){
if(!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& this.isWithTokenRoute()){
if(window.location.href.indexOf(this.route('feedback.customer')) !== 0){
window.location.href = window.location.href.indexOf(this.route('last_mile_delivery.login')) === 0 ? this.route('last_mile_delivery.login') : this.route('login')
}
}
(this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = [7, 8].includes(this.$store.getters.getCompanyModuleType) ? this.route('last_mile_delivery.dashboard') : this.route('dashboard') : '';
},
isProtectedRoute(){
const unprotectedRoutes = [this.route('login'), this.route('signup'), this.route('account.email.verification'), this.route('company.claim'), this.route('last_mile_delivery.login')];
if(window.location.href.indexOf(this.route('company.claim')) === 0) {
return false;
}
return !unprotectedRoutes.includes(window.location.href);
},
isWithTokenRoute(){
const unprotectedRoutesWithToken = [this.route('account.password.reset')];
return !window.location.href.includes(unprotectedRoutesWithToken);
}
}
}