UNPKG

vue-nuxt-permission

Version:

A unified permission system for Vue 3 and Nuxt 3 / Nuxt 4 with directives, guards, and async support.

82 lines (81 loc) 2.48 kB
import { Ref } from 'vue'; import { RouteLocationNormalized } from 'vue-router'; export type PermissionMode = "and" | "or" | "not" | "startWith" | "endWith" | "regex"; export interface PermissionObject { permissions: string[]; mode: PermissionMode; } export type PermissionValue = "*" | string | string[] | PermissionObject; export type PermissionsArray = string[] | Ref<string[]> | Ref<any>; export type DecryptHook = (raw: any) => string[] | Promise<string[]>; export interface GlobalConfig { permissions: PermissionsArray | null; developmentMode: boolean; decrypt?: DecryptHook; } export interface ConfigurePermissionOptions { developmentMode?: boolean; persist?: boolean; decrypt?: DecryptHook; transform?: DecryptHook; } export interface PluginOptions { permissions?: PermissionsArray | any; developmentMode?: boolean; fetchPermissions?: () => Promise<string[] | any>; persist?: boolean; decrypt?: DecryptHook; transform?: DecryptHook; } export interface RouteMetaWithPermissions { requiresAuth?: boolean; checkPermission?: boolean; permissions?: PermissionValue; isAuthRoute?: boolean; [key: string]: any; } export interface PermissionRoute { path: string; meta?: RouteMetaWithPermissions; children?: PermissionRoute[]; [key: string]: any; } export interface GuardOptions { authRoutes?: Array<{ path: string; }>; protectedRoutes?: PermissionRoute[]; getAuthState?: () => AuthState; loginPath?: string; homePath?: string; decrypt?: DecryptHook; transform?: DecryptHook; onDenied?: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void; onAllowed?: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void; } export interface AuthState { isAuthenticated: boolean; permissions?: string[] | any; user?: { permissions?: string[] | any; [key: string]: any; }; } declare global { interface HTMLElement { _vPermissionOriginalDisplay?: string; _vPermissionSkipUpdates?: boolean; _vPermissionParent?: Node | null; _vPermissionNextSibling?: Node | null; _vPermissionComment?: Comment | null; } } declare module "vue-router" { interface RouteMeta { requiresAuth?: boolean; checkPermission?: boolean; permissions?: PermissionValue; isAuthRoute?: boolean; } } //# sourceMappingURL=index.d.ts.map