Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

application specific: add paths per role #465

Open
github-actions bot opened this issue Apr 20, 2023 · 0 comments
Open

application specific: add paths per role #465

github-actions bot opened this issue Apr 20, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

application specific: add paths per role

switch (user.role) {

case ROLE.ADMIN:

return ROUTES.CUSTOMERS;

case ROLE.USER:

return ROUTES.CUSTOMERS.path + '/' + user.username;

default:

return ROUTES.LOGIN;

}

eslint-disable-next-line sonarjs/cognitive-complexity,consistent-return

// TODO application specific: add paths per role

import { boot } from 'quasar/wrappers';
import { Router, RouteRecordRaw } from 'vue-router';

import { isModuleActive } from '../flox';
import { MODULES } from '../flox/enum/MODULES';
import UserEntity from '../flox/modules/auth/entities/user.entity';
import { fetchMyUser } from '../flox/modules/auth/services/user.service';
import { useAuthStore } from '../flox/modules/auth/stores/auth.store';
import ROUTES, { CONSTRAINED_ROUTES, PUBLIC_ROUTES } from '../router/routes';

// eslint-disable-next-line import/no-mutable-exports
let routerInstance: Router;

/**
 * Returns the component of the dashboard for the currently logged-in user
 *
 * @param user - the user, if any
 * @param $authStore - authentication store
 * @returns the layout component
 */
function getUserRoleRoute(
  user: UserEntity | null,
  $authStore: ReturnType<typeof useAuthStore>
): RouteRecordRaw {
  // Non-logged in: Redirect to log in
  if (!user) {
    $authStore.setCognitoUser(undefined);
    $authStore.setUserSession(undefined);
    return ROUTES.LOGIN;
  }

  return ROUTES.HOME;
  // TODO application specific: add paths per role
  // switch (user.role) {
  //   case ROLE.ADMIN:
  //     return ROUTES.CUSTOMERS;
  //   case ROLE.USER:
  //     return ROUTES.CUSTOMERS.path + '/' + user.username;
  //   default:
  //     return ROUTES.LOGIN;
  // }
}

export default boot(({ router }) => {
  const $authStore = useAuthStore();
  routerInstance = router;
  // eslint-disable-next-line sonarjs/cognitive-complexity,consistent-return
  router.beforeEach(async (to) => {
    // Verify valid authentication
    const { loggedIn } = $authStore;

    // TODO: Add as part of sharing module
    // Case 1: trying to access non-public route while not logged in

c34afcdbe6cf8bf4dc8cd9656b2379056bd551f0

@github-actions github-actions bot added the todo label Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants