You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{boot}from'quasar/wrappers';importROUTES,{CONSTRAINED_ROUTES,PUBLIC_ROUTES}from'../router/routes';import{Router}from'vue-router';import{root}from'src/store';import{User}from'src/data/types/User';import{Context,Module}from'vuex-smart-module';importAuthStatefrom'src/store/authentication/state';importAuthGettersfrom'src/store/authentication/getters';importAuthActionsfrom'src/store/authentication/actions';importAuthMutationsfrom'src/store/authentication/mutations';import{fetchMyUser}from'src/helpers/data/fetch-helpers';import{isModuleActive}from'src/flox';import{MODULES}from'src/flox/MODULES';letrouterInstance: Router;exportdefaultboot(({ router, store })=>{// Get auth module within store (useAuth not working here)const$authStore=root.context(store).modules.authModule;routerInstance=router;// eslint-disable-next-line sonarjs/cognitive-complexityrouter.beforeEach(async(to)=>{// Verify valid authenticationconstloggedIn=$authStore.getters.getLoggedInStatus();// TODO: Add as part of sharing module// Case 1: trying to access non-public route while not logged in// if (// !loggedIn &&// !PUBLIC_ROUTES.some((publicRoute) => {// return publicRoute.path === to.path;// })// ) {// // Check if it is a public link// if (to.query.key) {// const validKey = await fetchKeyValid(to.path, to.query.key as string);// if (validKey) {// return true;// }// }// return ROUTES.LOGIN;// } elseif(loggedIn){constuser=awaitfetchMyUser();// Case 2: going to login when logged in, or to default path '/'if(!user||to.path===ROUTES.LOGIN.path||to.path==='/'){returngetUserRoleRoute(user,$authStore);}// Case 3: role module is active and route has some constraintsif(isModuleActive(MODULES.ROLES)){constmatchingConstrainedRoute=CONSTRAINED_ROUTES.find((constrainedRoute)=>constrainedRoute.path===to.path);if(matchingConstrainedRoute){consthasFullAccess=matchingConstrainedRoute.allowedRoles.includes(user.role);if(!hasFullAccess){returngetUserRoleRoute(user,$authStore);}}}}else{// Default case: disallow access if not publicif(!PUBLIC_ROUTES.some((publicRoute)=>publicRoute.path===to.path)){returnROUTES.LOGIN}}});});// Router instance for use in Vue componentsexport{routerInstance};/** * Returns the component of the dashboard for the currently logged in user * @param {User|null} user - the user, if any * @param {Context<Module<AuthState, AuthGetters, AuthMutations, AuthActions, Record<string, any>>>} $authStore - authentication store * @returns {any} - the layout component */functiongetUserRoleRoute(user: User|null,$authStore: Context<Module<AuthState,AuthGetters,AuthMutations,AuthActions,Record<string,any>>>){// Non-logged in: Redirect to loginif(!user){$authStore.mutations.setCognitoUser(undefined);$authStore.mutations.setUserSession(undefined);returnROUTES.LOGIN;}returnROUTES.SAMPLE// 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;// }}
455451358a2a89c7c0400b7e759acd78834fdec6
The text was updated successfully, but these errors were encountered:
Add as part of sharing module
Case 1: trying to access non-public route while not logged in
if (
!loggedIn &&
!PUBLIC_ROUTES.some((publicRoute) => {
return publicRoute.path === to.path;
})
) {
// Check if it is a public link
if (to.query.key) {
const validKey = await fetchKeyValid(to.path, to.query.key as string);
if (validKey) {
return true;
}
}
return ROUTES.LOGIN;
} else
flox/frontend/src/boot/router.ts
Line 26 in ded0256
455451358a2a89c7c0400b7e759acd78834fdec6
The text was updated successfully, but these errors were encountered: