---
title: "Server utilities"
description: "Full signatures for the auto-imported server helpers: the base module's fetch and preload helpers, and backendAuth for a signed-in caller's calls."
canonical_url: "https://nuxt-backend.dev/docs/reference/nuxt/server-utilities"
---
# Server utilities

> Full signatures for the auto-imported server helpers: the base module's fetch and preload helpers, and backendAuth for a signed-in caller's calls.

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.

The module auto-imports a few helpers in `server/` and in your server routes, so the app's server can call the backend for a request. This page gives their signatures. The fetch and preload helpers are the base module's, and mirror the official `convex/nextjs` surface. `backendAuth` is the package's: the same calls, made as the signed-in person.

There are no agent-tool utilities: the end-user MCP endpoint, and with it the helpers that wrote its tools, waits for a later release ([Roadmap](https://nuxt-backend.dev/docs/start/roadmap)).

## Fetch and preload

```ts
function fetchQuery<Q extends FunctionReference<'query'>>(
  query: Q, ...args: ArgsAndOptions<Q, NuxtConvexOptions>      // (args?, options?)
): Promise<FunctionReturnType<Q>>

function fetchMutation<M extends FunctionReference<'mutation'>>(
  mutation: M, ...args: ArgsAndOptions<M, NuxtConvexOptions>
): Promise<FunctionReturnType<M>>

function fetchAction<A extends FunctionReference<'action'>>(
  action: A, ...args: ArgsAndOptions<A, NuxtConvexOptions>
): Promise<FunctionReturnType<A>>

function preloadQuery<Q extends FunctionReference<'query'>>(
  query: Q, ...args: ArgsAndOptions<Q, NuxtConvexOptions>
): Promise<Preloaded<Q>>

function preloadedQueryResult<Q extends FunctionReference<'query'>>(preloaded: Preloaded<Q>): FunctionReturnType<Q>

interface NuxtConvexOptions {
  token?: string  // a JWT, for an authenticated call
  url?: string    // defaults to the resolved backend URL
}
```

## `backendAuth(event)`

The signed-in caller's backend client for one request: the base module's `convexAuth(event)`, whose calls are [reported](https://nuxt-backend.dev/docs/ship/operate/monitoring#what-gets-reported) with the function they ran when they fail with a crash or an `unavailable` refusal. It takes the event that `defineEventHandler` passes, from `nuxt/server` or the auto-imported one, or `useRequestEvent()` during server rendering. The option and service types are exported from the package entry:

```ts [server/api/stories.get.ts]
import { defineEventHandler } from 'nuxt/server'
import { api } from '#backend/api'

export default defineEventHandler(async (event) => {
  const { fetchAuthQuery } = backendAuth(event)
  return fetchAuthQuery(api.stories.list)
})
```

```ts
import type { BackendAuthOptions, BackendAuthService } from 'nuxt-backend'

function backendAuth(event: ConvexAuthEvent, opts?: BackendAuthOptions): BackendAuthService
// ConvexAuthEvent: the event a Nuxt server route or middleware receives
type BackendAuthOptions = GetTokenOptions & { convexSiteUrl?: string }

interface BackendAuthService {
  getToken(): Promise<string | undefined>
  isAuthenticated(): Promise<boolean>
  handler(): Promise<Response>
  preloadAuthQuery<Q extends FunctionReference<'query'>>(query: Q, args?: Q['_args']): Promise<Preloaded<Q>>
  fetchAuthQuery<Q extends FunctionReference<'query'>>(query: Q, args?: Q['_args']): Promise<FunctionReturnType<Q>>
  fetchAuthMutation<M extends FunctionReference<'mutation'>>(mutation: M, args?: M['_args']): Promise<FunctionReturnType<M>>
  fetchAuthAction<A extends FunctionReference<'action'>>(action: A, args?: A['_args']): Promise<FunctionReturnType<A>>
}
```

The token is fetched once per request: every `backendAuth(event)` for the same request shares it through `event.context`.

<tip to="https://nuxt-backend.dev/docs/build/data/read-write/server-rendering">

For server rendering and preloading, see Render data on the server.

</tip>


## Sitemap

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