---
title: "useAuth"
description: "useAuth, auto-imported in the app: its options, return value and types."
canonical_url: "https://nuxt-backend.dev/docs/reference/api/use-auth"
---
# useAuth

Version: nuxt-backend 0.6.x · Tab: Reference · Kind: reference · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

## Interfaces

### UseAuthReturn

Defined in: [src/runtime/vue/composables/use-auth.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts)

What `useAuth()` returns: the session, the role, an administrator's visit, and signing out.

#### Properties

<table>
<thead>
  <tr>
    <th>
      Property
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <a id="user">
        
      </a>
      
       <code>
        user
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<a href="#backenduser">
        <code>
          BackendUser
        </code>
      </a>
      
       | <code>
        null
      </code>
      
      >
    </td>
    
    <td>
      The signed-in account, or <code>
        null
      </code>
      
       when signed out or still loading.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="session">
        
      </a>
      
       <code>
        session
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        any
      </code>
      
      >
    </td>
    
    <td>
      The session this browser holds, or <code>
        null
      </code>
      
      .
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="role">
        
      </a>
      
       <code>
        role
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        string
      </code>
      
      >
    </td>
    
    <td>
      The app-wide role; <code>
        'user'
      </code>
      
       when signed out or unset.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="hasrole">
        
      </a>
      
       <code>
        hasRole
      </code>
    </td>
    
    <td>
      (<code>
        role
      </code>
      
      ) => <code>
        boolean
      </code>
    </td>
    
    <td>
      Whether the account holds the app-wide role, or any one of several.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="issignedin">
        
      </a>
      
       <code>
        isSignedIn
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      Whether someone is signed in, read from the base module's auth state.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="isready">
        
      </a>
      
       <code>
        isReady
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      Whether a signed-in read can go: someone is signed in, and the backend connection holds their token. On every page load <code>
        isSignedIn
      </code>
      
       turns <code>
        true
      </code>
      
       a moment sooner, from the session, while the token is still on its way, and a query of a signed-in tier (<code>
        authed
      </code>
      
      , <code>
        workspace
      </code>
      
      , <code>
        admin
      </code>
      
      ) started in that moment is refused <code>
        unauthenticated
      </code>
      
      . Skip such a query until this is <code>
        true
      </code>
      
      : <code>
        useQuery(api.strips.list, () => (isReady.value ? {} : 'skip'))
      </code>
      
      .
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="isloading">
        
      </a>
      
       <code>
        isLoading
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while the session is still resolving.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="impersonating">
        
      </a>
      
       <code>
        impersonating
      </code>
    </td>
    
    <td>
      <code>
        ComputedRef
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        true
      </code>
      
       while an administrator is visiting the account: <code>
        user
      </code>
      
       is the account visited, and every sensitive action is refused. The <code>
        impersonation
      </code>
      
       notice of <code>
        <BackendNotices>
      </code>
      
       says so on every page, and <code>
        useAdmin().stopImpersonating()
      </code>
      
       ends the visit.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="signout">
        
      </a>
      
       <code>
        signOut
      </code>
    </td>
    
    <td>
      () => <code>
        Promise
      </code>
      
      <<code>
        void
      </code>
      
      >
    </td>
    
    <td>
      Sign this browser out. Rejects on failure. The app navigates after it on its own: a sign-out made here never sends the person to the sign-in page with <code>
        ?redirect=
      </code>
      
      , as a session that ends elsewhere does.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

## Type Aliases

### BackendUser

```ts
type BackendUser = BetterAuthUser & {
  banned?: boolean | null;
};
```

Defined in: [src/runtime/vue/composables/use-auth.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts)

The signed-in account, as the session carries it: `id`, `email`, `name`, `role`, `banned`, `image`, `locale`, …

#### Type Declaration

<table>
<thead>
  <tr>
    <th>
      Name
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Defined in
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        banned?
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
      
       | <code>
        null
      </code>
    </td>
    
    <td>
      Whether the account is banned.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts" rel="nofollow">
        src/runtime/vue/composables/use-auth.ts
      </a>
    </td>
  </tr>
</tbody>
</table>

---

### BackendSession

```ts
type BackendSession = NonNullable<NonNullable<BetterAuthSession["value"]["data"]>["session"]>;
```

Defined in: [src/runtime/vue/composables/use-auth.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts)

The session this browser holds: its `id`, `expiresAt`, the active workspace, and who opened it.

## Functions

### useAuth()

```ts
function useAuth(): UseAuthReturn;
```

Defined in: [src/runtime/vue/composables/use-auth.ts](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-auth.ts)

Who is signed in: the session, the app-wide role, whether an
administrator is visiting, and signing out. Nothing else: sign-in is
`useLoginFlow`'s, passkeys are `usePasskeys`', the profile, the export and
the deletion are `useAccount`'s, and ending a visit is `useAdmin`'s.

#### Returns

[`UseAuthReturn`](#useauthreturn)

#### Example

```vue
<script setup lang="ts">
const { user, isSignedIn, isReady, hasRole, signOut } = useAuth()
// A read of your own signed-in functions waits for the backend to hold the token.
const strips = useQuery(api.strips.list, () => (isReady.value ? {} : 'skip'))
</script>

<template>
  <p v-if="isSignedIn">
    {{ user?.name }}
    <NuxtLink v-if="hasRole('admin')" to="/admin">Admin</NuxtLink>
    <button @click="signOut().then(() => navigateTo('/'))">Sign out</button>
  </p>
</template>
```


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
