Skip to content

application specific: add paths per role #465

Description

@github-actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions