Files
exchange-2.0/resources/assets/vue/general/mixins/guards.js
T

33 lines
1.6 KiB
JavaScript
Vendored

export default {
methods: {
routesGuard(){
(!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('login') : '';
(this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : '';
},
isProtectedRoute(){
// Compare pathname only (without query parameters) to handle affiliate tracking links
const currentPath = window.location.pathname;
// Define unprotected routes as pathnames directly
// This ensures affiliate tracking links like /signup?tracking=xxx work correctly
const unprotectedPaths = [
'/', // login route
'/signup', // signup route
'/account/email/verification' // email verification route (may have token param)
];
// Check if current path matches any unprotected path
// For email verification, check if path starts with the base path
if (currentPath.startsWith('/account/email/verification')) {
return false; // It's an email verification route (unprotected)
}
// Check exact matches for other routes
return !unprotectedPaths.includes(currentPath);
},
isWithTokenRoute(){
return window.location.href.includes(this.route('account.password.reset')) || window.location.href.includes('/account/email/verification');
}
}
}