Skip to content

Composables

Composables live in src/resources/src/composables/.

useAuth

The useAuth composable provides reactive user state. The auth Pinia store (stores/auth.ts) calls setUser() / clearUser() internally — components read from useAuth().

ts
import { useAuth } from "@/composables/useAuth";

Return values

PropertyTypeDescription
userReadonly<Ref<AuthUser | null>>Current authenticated user (readonly)
isAuthenticatedComputedRef<boolean>true when a user is logged in
setUser(user: AuthUser | null) => voidSet the user (called by auth store)
clearUser() => voidClear the user (called by auth store)

Types

ts
type AuthUser = Record<string, unknown> & {
  id?: string | number;
  name?: string;
  role?: RoleLike | null;
  roles?: RoleLike[] | null;
};

type RoleLike = {
  id?: string | number;
  name?: string;
  title?: string;
  slug?: string;
};

Usage

vue
<script setup lang="ts">
import { useAuth } from "@/composables/useAuth";

const { user, isAuthenticated } = useAuth();
</script>

<template>
  <div v-if="isAuthenticated">
    Welcome, {{ user?.name }}
  </div>
  <div v-else>
    Please log in.
  </div>
</template>

hasRole

Standalone function to check if the current user has a specific role.

ts
import { hasRole } from "@/composables/useAuth";

// Check if user has "admin" role
if (hasRole("admin")) {
  // show admin panel
}

// Check if user has any role
if (hasRole()) {
  // user has at least one role
}

// Check if user has any of the listed roles
if (hasRole("admin", "editor")) {
  // user is admin OR editor
}

Role matching is case-insensitive and checks name, title, or slug on each role object.

authUser

Standalone computed that returns the current user or an empty object:

ts
import { authUser } from "@/composables/useAuth";

// authUser.value is AuthUser (never null — defaults to {})

Removed composables

The following composables were previously re-exports and have been removed. Import directly from their plugin files instead:

RemovedReplace with
@/composables/useGumimport { useGum, useGumForm } from "@/plugins/gum"
@/composables/usePulseimport { pulse } from "@/plugins/pulse"
@/composables/useDialogimport { dialog } from "@/plugins/dialog"
@/composables/useBrowserDetectimport { browserDetect } from "@/plugins/browserDetect"

Released under the MIT License.