---
title: Sign-in and tokens
description: How Google sign-in through Better Auth becomes a Convex identity, and how MCP clients get access.
---

Better Auth runs inside the **api worker** and stores users, sessions and OAuth clients in D1.

1. **Sign in**

    The iPhone app uses Better Auth's Expo plugin. The Mac app opens `/native/sign-in` in `ASWebAuthenticationSession` and gets back `whyo://auth?token=…`.

2. **Get a Convex token**

    Apps swap their session for a 15-minute RS256 JWT at `/api/auth/token`. Its audience is `convex`.

3. **Convex checks it**

    Convex verifies the token against the worker's JWKS (or `AUTH_JWKS` in local development). Every query and mutation runs as that user.

## MCP clients

The api worker is also an OAuth 2.1 server (Better Auth's OAuth provider plugin), with dynamic client registration for MCP clients. A token issued for the MCP server has the MCP URL as its audience. The mcp worker verifies it and forwards it to Convex, which accepts that audience too.
