Skip to content

requireGroups

Overview

Require the user to have certain groups, or show a toast message for denial.

Signature

requireGroups(instance, toastArgs, groups, redirectTo, to, router, pinia)

Parameters

NameTypeRequiredDescription
instanceAppyesThe Vue app instance.
toastArgsobjectyesToast message options.
groupsstring[]yesThe groups the user must belong to at least one.
redirectTostring | RouteLocationAsRelativeGeneric | RouteLocationAsPathGenericyesWhere to redirect if not authorized.
toRouteLocationNormalizedLoadedGenericyesThe target route.
routerRouteryesThe router instance.
piniaPiniayesThe Pinia instance.

toastArgs Properties

NameTypeRequiredDefaultDescription
detailstringno
lifenumberno
severitystringno
summarystring

Returns

Promise

True if authorized, or redirect route.

Examples

js
import { requireGroups } from "@vueda/router/guards";
import { createRouter, createWebHistory } from "vue-router";

const toastArgs = {
  summary: "Permission Denied",
  detail: "You do not have permission to access",
  severity: "error",
};

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/groups-required/',
      name: 'groups-required',
      component: () => import('@/views/ViewGroupsRequired.vue'),
      beforeEnter: (to, from) =>
        requireGroups(app, toastArgs, ["group1", "group2"], { name: "access-denied" }, to, router),
    },
    // other routes
  ],
});

export default router;

Source

client/lib/router/guards.js:261

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2