API

Composables

API reference for UNuxt composables

Reference for the composables available in UNuxt.

useUserSession

Access the current user session and authentication state.

const { user, session, loggedIn, fetch, clear } = useUserSession()

Returns

PropertyTypeDescription
userRef<User | null>Current user object
sessionRef<Session | null>Current session data
loggedInComputedRef<boolean>Whether user is authenticated
fetch() => Promise<void>Refresh session from server
clear() => Promise<void>Clear session and logout

Example

<script setup lang="ts">
const { user, loggedIn, clear } = useUserSession()

async function logout() {
  await clear()
  navigateTo('/auth/login')
}
</script>

useOrganization

Manage organization state and permissions.

const {
  organizations,
  activeOrganization,
  setActiveOrganization,
  hasPermission
} = useOrganization()

Returns

PropertyTypeDescription
organizationsRef<Organization[]>User's organizations
activeOrganizationRef<Organization | null>Currently active organization
setActiveOrganization(id: string) => Promise<void>Switch active organization
hasPermission(permission: string) => booleanCheck user permission

Example

<script setup lang="ts">
const { activeOrganization, hasPermission } = useOrganization()

const canManageMembers = computed(() => hasPermission('member:invite'))
</script>

useTheme

Control application theming and color mode.

const { primaryColor, colorMode, setTheme } = useTheme()

Returns

PropertyTypeDescription
primaryColorRef<string>Current primary color
colorModeRef<'light' | 'dark'>Current color mode
setTheme(color: string, mode: string) => voidUpdate theme

Example

<script setup lang="ts">
const { primaryColor, colorMode, setTheme } = useTheme()

function applyTheme(color: string) {
  setTheme(color, colorMode.value)
}
</script>

use2FA

Manage two-factor authentication.

const { enable2FA, verify2FA, disable2FA } = use2FA()

Returns

PropertyTypeDescription
enable2FA() => Promise<{ qrCode: string }>Enable 2FA, returns QR code
verify2FA(code: string) => Promise<void>Verify 2FA code
disable2FA(code: string) => Promise<void>Disable 2FA

Example

<script setup lang="ts">
const { enable2FA, verify2FA } = use2FA()
const qrCode = ref('')
const verificationCode = ref('')

async function setup2FA() {
  const { qrCode: code } = await enable2FA()
  qrCode.value = code
}

async function confirm2FA() {
  await verify2FA(verificationCode.value)
}
</script>
Copyright © 2026