Created
February 7, 2020 15:53
-
-
Save dumebi/b2b40e32f4ef4ad439a85fa55e5f7a85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.requiresAuth = (to, from, next, Bacexdata) => { | |
if (to.matched.some(record => record.meta.requiresUserAuth) && Bacexdata.user.is_auth === false) { | |
Bacexdata.user.error = 'You need to log in before you can perform this action.' | |
next({ | |
path:'/login', | |
query: { redirect: to.fullPath } | |
}) | |
} else if (to.matched.some(record => record.meta.requiresAdminAuth) && Bacexdata.admin.is_auth === false) { | |
// console.log(to) | |
Bacexdata.admin.error = 'You need to log in before you can perform this action.' | |
next({ | |
path:'/admin/login', | |
query: { redirect: to.fullPath } | |
}) | |
} else if (to.matched.some(record => record.meta.requiresCompanyAuth) && Bacexdata.company.is_auth === false) { | |
Bacexdata.company.error = 'You need to log in before you can perform this action.' | |
next({ | |
path:'/business/login', | |
query: { redirect: to.fullPath } | |
}) | |
} else { | |
next() | |
} | |
} | |
exports.requiresNoAuth = (to, from, next, Bacexdata) => { | |
if (to.matched.some(record => record.meta.requiresNoUserAuth) && Bacexdata.user.is_auth === true) { | |
next('/dashboard') | |
} else if (to.matched.some(record => record.meta.requiresNoAdminAuth) && Bacexdata.admin.is_auth === true) { | |
next('/admin/') | |
} else if (to.matched.some(record => record.meta.requiresNoCompanyAuth) && Bacexdata.company.is_auth === true) { | |
next('/business/') | |
} else { | |
next() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment