Skip to content

useUser ​

Provides reactive state about the authenticated user — guest status, roles, timezone, company validity — and proxies the authorization helpers from useAuthorization.

File: vue/src/js/hooks/useUser.js


Usage ​

js
import { useUser } from '@/hooks'

const {
  isGuest,
  isSuperAdmin,
  isClient,
  timezone,
  validCompany,
  showBillingBanner,
  can,
  isYou,
  hasRoles
} = useUser()
html
<template v-if="!isGuest">
  <span>Welcome back</span>
</template>

<v-btn v-if="can('manage-billing')">Billing</v-btn>

Returns ​

State ​

NameTypeDescription
isGuestComputedRef<Boolean>true when no user is authenticated (store.getters.isGuest)
isSuperAdminComputedRef<Boolean>true when the user has the super-admin role
isClientComputedRef<Boolean>true when the user has the client role
timezoneComputedRef<String>User's timezone string (e.g. 'Europe/Istanbul'), defaults to 'Europe/London'
validCompanyComputedRef<Boolean>true when the user's company has passed validation (store.state.user.valid_company)
showBillingBannerComputedRef<Boolean>true when the billing banner should be displayed (store.state.user.profile.show_billing_banner)

Proxied from useAuthorization ​

NameSignatureDescription
can(permission, moduleName?) => BooleanPermission check — see useAuthorization
isYou(id) => BooleanReturns true when id matches the authenticated user's id
hasRoles(roles: String|Array) => BooleanReturns true when the user has at least one of the given roles

Notes ​

  • useUser is a convenience wrapper — it combines Vuex user state with the authorization helpers so components only need one import instead of two.
  • For permission-only logic, prefer useAuthorization directly to keep the dependency minimal.

See Also ​