---
title: "Sign in with Convex auth"
description: "Run Convex Auth in place of Better Auth: sign-in only, through the base module's @convex-dev/auth integration, with the package's pages, page guard, workspaces, billing, AI credits and account features off."
canonical_url: "https://nuxt-backend.dev/docs/build/auth/convex-auth"
---
# Sign in with Convex auth

> Run Convex Auth in place of Better Auth: sign-in only, through the base module's @convex-dev/auth integration, with the package's pages, page guard, workspaces, billing, AI credits and account features off.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: experimental

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.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/nuxt/auth-provider.ts)

Better Auth is the package's auth, and stays the default: every page, the page guard, workspaces, billing, AI credits and the account features run on its accounts. An app that wants [Convex Auth](https://docs.convex.dev/auth/convex-auth) instead can switch to it, for sign-in only. The package then runs nuxt-convex-module's own Convex Auth integration and turns off what Better Auth carries, rather than rebuilding it on Convex Auth. It is experimental ([Stability](https://nuxt-backend.dev/docs/ship/releases/stability)).

## Turn it on

```bash
pnpm add @convex-dev/auth
```

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['nuxt-backend'],
  backend: {
    auth: 'convex-auth',
  },
})
```

The base module then gets `betterAuth: false` and `convexAuth: { loginPath }`, its Polar integration off, and the package's sign-in path as the page its `convex-auth` middleware redirects to (`backend.pages.login`, `/login` by default). Without `@convex-dev/auth` installed, the base module says so at startup.

## Set up the backend

Follow [Convex Auth's setup](https://docs.convex.dev/auth/convex-auth): its component mounted as `auth` in `backend/convex.config.ts`, and an `auth.ts` with the sign-in methods you want. Its access tokens are signed with the deployment's own key, so `backend/auth.config.ts` lists Convex Auth's provider in place of the package's Better Auth config:

```ts [backend/auth.config.ts]
import type { AuthConfig } from 'convex/server'
import { convexAuthProvider } from '@convex-dev/auth/server'

export default {
  providers: [convexAuthProvider()],
} satisfies AuthConfig
```

`@convex-dev/auth` signs people in with emailed magic links, OAuth providers (Google, Apple, GitHub, Discord), passkeys and passwords.

Then wire the Nuxt side as nuxt-convex-module's [Convex Auth guide](https://nuxt-convex-module.dev/components/convex-auth) shows. For an app that renders on the server, that is one file, `server/convex-auth.ts`, whose `setupConvexAuthNuxt` lists the functions that start a session. Its sign-in composables (`useSendEmailMagicLink`, `useSignInWithGithub`, `useSignInWithUsernamePasskey`, …), `useAuthActions` and `<ConvexAuthProvider>` stay registered in this mode: the package hides the base module's brand-named surface in a Better Auth app, but not that one.

## Guard a page

The package's page guard, `definePageMeta({ auth })`, reads the Better Auth session, so it is not registered. With cookie sessions (the `server/convex-auth.ts` file above), use the base module's middleware:

```vue [app/pages/studio.vue]
<script setup lang="ts">
definePageMeta({ middleware: 'convex-auth' })
</script>
```

The base module registers that middleware only once `server/convex-auth.ts` exists. An app that keeps the session in browser storage has no middleware to name; it guards a page in the page itself, with `<Authenticated>` and `<Unauthenticated>` ([Convex Auth in nuxt-convex-module](https://nuxt-convex-module.dev/components/convex-auth#choose-where-the-session-lives)).

In a backend function, read the account with `getAuthUserId(ctx)` from `@convex-dev/auth/server`. The package's tiers (`authed`, `workspace`, `admin`) are written for Better Auth's accounts: leave them out in this mode.

## What is off

<table>
<thead>
  <tr>
    <th>
      Off in this mode
    </th>
    
    <th>
      Why
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      The ready-made pages (<code>
        /login
      </code>
      
      , <code>
        /profile
      </code>
      
      , <code>
        /security
      </code>
      
      , <code>
        /settings
      </code>
      
      , <code>
        /pricing
      </code>
      
      , <code>
        /admin
      </code>
      
      , …)
    </td>
    
    <td>
      Each reads the Better Auth session. Write your own sign-in page with the base module's composables.
    </td>
  </tr>
  
  <tr>
    <td>
      The page guard and its 403 page
    </td>
    
    <td>
      It reads the Better Auth session.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useAuth()
      </code>
      
       and the Nitro <code>
        backendAuth(event)
      </code>
    </td>
    
    <td>
      Both are the Better Auth session. <code>
        useAuthActions()
      </code>
      
       and <code>
        setupConvexAuthNuxt
      </code>
      
       stand in.
    </td>
  </tr>
  
  <tr>
    <td>
      Workspaces, roles, the admin console and impersonation
    </td>
    
    <td>
      They are Better Auth's organization and admin plugins.
    </td>
  </tr>
  
  <tr>
    <td>
      Billing, gifts and AI credits
    </td>
    
    <td>
      They belong to a Better Auth account and its workspace.
    </td>
  </tr>
  
  <tr>
    <td>
      The account features: export, deletion, sessions, sign-in alerts, consents
    </td>
    
    <td>
      They run on Better Auth's account and session tables.
    </td>
  </tr>
  
  <tr>
    <td>
      The startup preflight of <code>
        AUTH_SECRET
      </code>
      
       and <code>
        SITE_URL
      </code>
    </td>
    
    <td>
      They are Better Auth's. Startup says once which mode runs instead.
    </td>
  </tr>
</tbody>
</table>

`npx nuxt-backend doctor` reports the mode as [`auth-provider`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#auth-provider), and leaves out the checks that do not apply: `AUTH_SECRET`, `SITE_URL`, the `/api/auth` proxy and billing.

## Related

- [The Convex Auth example](https://github.com/qruto/nuxt-backend/tree/main/examples/convex-auth): this mode in a whole app, with a username and password sign-in, cookie sessions and a guarded page. Create it with `npm create nuxt@latest my-app -- -t gh:qruto/nuxt-backend/examples/convex-auth`.
- [Convex Auth in nuxt-convex-module](https://nuxt-convex-module.dev/components/convex-auth): the composables, cookie sessions and every sign-in method.
- [Convex Auth](https://docs.convex.dev/auth/convex-auth): the backend setup.
- [Module options](https://nuxt-backend.dev/docs/reference/configuration/module-options): `auth` beside the rest.


## Sitemap

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