Skip to content

Instantly share code, notes, and snippets.

@dumebi
Created February 7, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumebi/b2b40e32f4ef4ad439a85fa55e5f7a85 to your computer and use it in GitHub Desktop.
Save dumebi/b2b40e32f4ef4ad439a85fa55e5f7a85 to your computer and use it in GitHub Desktop.
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