---
title: "better-auth/server"
description: "Server-side Better Auth + Convex integration for Nuxt — generated TypeScript API reference for nuxt-convex-module/better-auth/server."
canonical_url: "https://nuxt-convex-module.dev/api-reference/reference/better-auth/server"
---
# better-auth/server

Server-side Better Auth + Convex integration for Nuxt.

Provides [convexAuth](#convexauth) for Nuxt server handlers: it takes the H3
`H3Event` every Nuxt server route, API handler and server middleware
receives, and returns a request-scoped, authenticated Convex client.

## Interfaces

### ConvexAuthService

Defined in: [src/runtime/better-auth/nuxt/server.ts:170](https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L170)

Per-request Better Auth + Convex helper returned by [convexAuth](#convexauth).

#### Properties

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

<tbody>
  <tr>
    <td>
      <a id="gettoken">
        
      </a>
      
       <code>
        getToken
      </code>
    </td>
    
    <td>
      () => <code>
        Promise
      </code>
      
      <<code>
        string
      </code>
      
       | <code>
        undefined
      </code>
      
      >
    </td>
    
    <td>
      Convex JWT for the current user, or <code>
        undefined
      </code>
      
       when not authenticated.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L172" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:172
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="handler">
        
      </a>
      
       <code>
        handler
      </code>
    </td>
    
    <td>
      () => <code>
        Promise
      </code>
      
      <<code>
        Response
      </code>
      
      >
    </td>
    
    <td>
      Proxy a Better Auth route to the configured Convex site URL.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L174" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:174
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="isauthenticated">
        
      </a>
      
       <code>
        isAuthenticated
      </code>
    </td>
    
    <td>
      () => <code>
        Promise
      </code>
      
      <<code>
        boolean
      </code>
      
      >
    </td>
    
    <td>
      <code>
        true
      </code>
      
       when the current request has a valid Convex auth token.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L176" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:176
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="preloadauthquery">
        
      </a>
      
       <code>
        preloadAuthQuery
      </code>
    </td>
    
    <td>
      <<code>
        Query
      </code>
      
      >(<code>
        query
      </code>
      
      , ...<code>
        args
      </code>
      
      ) => <code>
        Promise
      </code>
      
      <<a href="https://nuxt-convex-module.dev/api-reference/reference/client#preloaded">
        <code>
          Preloaded
        </code>
      </a>
      
      <<code>
        Query
      </code>
      
      >>
    </td>
    
    <td>
      Preload a Convex query with the current user's auth token.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L178" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:178
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="fetchauthquery">
        
      </a>
      
       <code>
        fetchAuthQuery
      </code>
    </td>
    
    <td>
      <<code>
        Query
      </code>
      
      >(<code>
        query
      </code>
      
      , ...<code>
        args
      </code>
      
      ) => <code>
        Promise
      </code>
      
      <<a href="https://nuxt-convex-module.dev/api-reference/reference/client#functionreturntype">
        <code>
          FunctionReturnType
        </code>
      </a>
      
      <<code>
        Query
      </code>
      
      >>
    </td>
    
    <td>
      Execute a Convex query with the current user's auth token.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L183" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:183
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="fetchauthmutation">
        
      </a>
      
       <code>
        fetchAuthMutation
      </code>
    </td>
    
    <td>
      <<code>
        Mutation
      </code>
      
      >(<code>
        mutation
      </code>
      
      , ...<code>
        args
      </code>
      
      ) => <code>
        Promise
      </code>
      
      <<a href="https://nuxt-convex-module.dev/api-reference/reference/client#functionreturntype">
        <code>
          FunctionReturnType
        </code>
      </a>
      
      <<code>
        Mutation
      </code>
      
      >>
    </td>
    
    <td>
      Execute a Convex mutation with the current user's auth token.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L188" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:188
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <a id="fetchauthaction">
        
      </a>
      
       <code>
        fetchAuthAction
      </code>
    </td>
    
    <td>
      <<code>
        Action
      </code>
      
      >(<code>
        action
      </code>
      
      , ...<code>
        args
      </code>
      
      ) => <code>
        Promise
      </code>
      
      <<a href="https://nuxt-convex-module.dev/api-reference/reference/client#functionreturntype">
        <code>
          FunctionReturnType
        </code>
      </a>
      
      <<code>
        Action
      </code>
      
      >>
    </td>
    
    <td>
      Execute a Convex action with the current user's auth token.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L193" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:193
      </a>
    </td>
  </tr>
</tbody>
</table>

## Type Aliases

### ConvexAuthOptions

```ts
type ConvexAuthOptions = GetTokenOptions & {
  convexUrl?: string;
  convexSiteUrl?: string;
};
```

Defined in: [src/runtime/better-auth/nuxt/server.ts:150](https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L150)

Options for [convexAuth](#convexauth).

Extends GetTokenOptions from `@convex-dev/better-auth/utils` with
an optional override for the Convex site URL.

#### Type Declaration

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

<tbody>
  <tr>
    <td>
      <code>
        convexUrl?
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Accepted for drop-in compatibility with upstream <code>
        convexBetterAuthNextJs
      </code>
      
       option objects and ignored — upstream requires but never reads it either; the deployment URL comes from runtime config.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L156" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:156
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        convexSiteUrl?
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Override the Convex site URL. Defaults to <code>
        runtimeConfig.convex.siteUrl
      </code>
      
      , then <code>
        runtimeConfig.public.convex.siteUrl
      </code>
      
      , then the <code>
        NUXT_PUBLIC_CONVEX_SITE_URL
      </code>
      
       process variable.
    </td>
    
    <td>
      <a href="https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L162" rel="nofollow">
        src/runtime/better-auth/nuxt/server.ts:162
      </a>
    </td>
  </tr>
</tbody>
</table>

## Variables

### convexBetterAuthNuxt

```ts
const convexBetterAuthNuxt: (event, opts?) => ConvexAuthService = convexAuth;
```

Defined in: [src/runtime/better-auth/nuxt/server.ts:360](https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L360)

Upstream-named alias of [convexAuth](#convexauth) — the mechanical rename target
for `@convex-dev/better-auth/nextjs`'s `convexBetterAuthNextJs` (framework
suffix `NextJs` → `Nuxt`). Unlike upstream's module-level factory (which
reads request state ambiently via `next/headers`), Nitro has no ambient
per-request context, so the H3 `event` is passed explicitly.

Create a per-request Better Auth + Convex helper for Nuxt server code.

Adapts the Better Auth + Convex server helper pattern to H3 events.

Call once at the top of a server route / event handler and destructure the
helpers you need. The auth token is fetched at most once per request — the
cache lives on `event.context`, so every `convexAuth(event)` instance for
the same request (server plugin, middleware, your route) shares one Better
Auth round-trip. Mirrors upstream's `React.cache`-wrapped `getToken`.

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        event
      </code>
    </td>
    
    <td>
      <code>
        H3Event
      </code>
    </td>
    
    <td>
      The H3 event from a Nuxt server route or middleware.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      <a href="#convexauthoptions">
        <code>
          ConvexAuthOptions
        </code>
      </a>
    </td>
    
    <td>
      Optional <a href="#convexauthoptions">
        ConvexAuthOptions
      </a>
      
      .
    </td>
  </tr>
</tbody>
</table>

#### Returns

[`ConvexAuthService`](#convexauthservice)

#### Examples

```ts
// server/api/profile.get.ts
export default defineEventHandler(async (event) => {
  const { fetchAuthQuery, isAuthenticated } = convexAuth(event)
  if (!await isAuthenticated()) {
    throw createError({ statusCode: 401 })
  }
  return fetchAuthQuery(api.users.current)
})
```

```ts
// pages/profile.vue — preloading data for SSR
const { data } = await useAsyncData(async () => {
  const event = useRequestEvent()!
  return convexAuth(event).preloadAuthQuery(api.users.current)
})
```

## Functions

### convexAuth()

```ts
function convexAuth(event, opts?): ConvexAuthService;
```

Defined in: [src/runtime/better-auth/nuxt/server.ts:236](https://github.com/qruto/nuxt-convex-module/blob/main/src/runtime/better-auth/nuxt/server.ts#L236)

Create a per-request Better Auth + Convex helper for Nuxt server code.

Adapts the Better Auth + Convex server helper pattern to H3 events.

Call once at the top of a server route / event handler and destructure the
helpers you need. The auth token is fetched at most once per request — the
cache lives on `event.context`, so every `convexAuth(event)` instance for
the same request (server plugin, middleware, your route) shares one Better
Auth round-trip. Mirrors upstream's `React.cache`-wrapped `getToken`.

#### Parameters

<table>
<thead>
  <tr>
    <th>
      Parameter
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        event
      </code>
    </td>
    
    <td>
      <code>
        H3Event
      </code>
    </td>
    
    <td>
      The H3 event from a Nuxt server route or middleware.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        opts?
      </code>
    </td>
    
    <td>
      <a href="#convexauthoptions">
        <code>
          ConvexAuthOptions
        </code>
      </a>
    </td>
    
    <td>
      Optional <a href="#convexauthoptions">
        ConvexAuthOptions
      </a>
      
      .
    </td>
  </tr>
</tbody>
</table>

#### Returns

[`ConvexAuthService`](#convexauthservice)

#### Examples

```ts
// server/api/profile.get.ts
export default defineEventHandler(async (event) => {
  const { fetchAuthQuery, isAuthenticated } = convexAuth(event)
  if (!await isAuthenticated()) {
    throw createError({ statusCode: 401 })
  }
  return fetchAuthQuery(api.users.current)
})
```

```ts
// pages/profile.vue — preloading data for SSR
const { data } = await useAsyncData(async () => {
  const event = useRequestEvent()!
  return convexAuth(event).preloadAuthQuery(api.users.current)
})
```


## Sitemap

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