fix: dashboard auth redirection and magic link login issues (#76)
Co-authored-by: Anwarul Islam <anwaarulislaam@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7668be50ae
commit
67f7e6a6d2
@@ -6,11 +6,28 @@ const isAdmin = () => {
|
||||
return user ? user.isAdmin : false;
|
||||
};
|
||||
|
||||
const GUEST_ROUTES = ['index', 'magic-link'];
|
||||
|
||||
const isGuestRoute = (to: unknown) => GUEST_ROUTES.includes(to as string);
|
||||
|
||||
/**
|
||||
* @module routers
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function
|
||||
* @name onBeforeRouteChange
|
||||
* @param {object} to
|
||||
* @param {object} from
|
||||
* @param {function} next
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
export default <HoppModule>{
|
||||
onBeforeRouteChange(to, from, next) {
|
||||
if (to.name !== 'index' && !isAdmin()) {
|
||||
if (!isGuestRoute(to.name) && !isAdmin()) {
|
||||
next({ name: 'index' });
|
||||
} else if (to.name === 'index' && isAdmin()) {
|
||||
} else if (isGuestRoute(to.name) && isAdmin()) {
|
||||
next({ name: 'dashboard' });
|
||||
} else {
|
||||
next();
|
||||
|
||||
Reference in New Issue
Block a user