/expo-stack:expo-stack-data-authfrom expo-stack
Wires Convex and Better Auth into an Expo Router app, managing cloud/self-hosted deployment, env vars, route guards, and debugging auth issues.
Ships in expo-stack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Defer to get-convex/agent-skills for Convex functions, schema and query performance, and to better-auth/skills for Better Auth options, plugins and security. This skill owns the seam: how the two meet inside an Expo Router app, and the env wiring that differs between cloud and self-hosted.
The app code is identical. Only the env vars and the CLI's target change.
| cloud | self-hosted | |
|---|---|---|
| CLI target | CONVEX_DEPLOYMENT (CONVEX_DEPLOY_KEY in CI) | CONVEX_SELF_HOSTED_URL + CONVEX_SELF_HOSTED_ADMIN_KEY |
API origin → EXPO_PUBLIC_CONVEX_URL | https://<name>.convex.cloud | backend CONVEX_CLOUD_ORIGIN, port 3210 |
Site origin (HTTP actions) → EXPO_PUBLIC_CONVEX_SITE_URL | https://<name>.convex.site | backend CONVEX_SITE_ORIGIN, port 3211 |
| Dashboard | dashboard.convex.dev | self-hosted, port 6791, authenticated with the admin key |
| Admin key | n/a | docker compose exec backend ./generate_admin_key.sh |
Never set both sets. Convex refuses to run with a mix of cloud and self-hosted vars, specifically so you cannot deploy to the wrong place. If you see that error, you have leftovers in .env.local — that is the guard working, not a bug.
Once either set is in place, npx convex dev, convex deploy, convex env set and codegen behave the same.
EXPO_PUBLIC_CONVEX_URL → the API origin. Used by ConvexReactClient.EXPO_PUBLIC_CONVEX_SITE_URL → the site origin (HTTP actions). Used by authClient.baseURL, and it is where Better Auth's routes are mounted.On cloud they differ only by TLD, which makes them easy to swap and hard to notice. Self-hosted they are two unrelated FQDNs on two ports. Symptoms of a swap: queries work but sign-in 404s, or auth works but no data arrives. Check this first whenever auth misbehaves.
convex/convex.config.tsimport { defineApp } from 'convex/server'
import betterAuth from '@convex-dev/better-auth/convex.config'
const app = defineApp()
app.use(betterAuth)
export default app
convex/auth.config.tsimport { getAuthConfigProvider } from '@convex-dev/better-auth/auth-config'
import type { AuthConfig } from 'convex/server'
export default {
providers: [getAuthConfigProvider()],
} satisfies AuthConfig
convex/auth.tsimport { createClient, type GenericCtx } from '@convex-dev/better-auth'
import { convex } from '@convex-dev/better-auth/plugins'
import { betterAuth } from 'better-auth/minimal'
import { expo } from '@better-auth/expo'
import { components } from './_generated/api'
import type { DataModel } from './_generated/dataModel'
import { query } from './_generated/server'
import authConfig from './auth.config'
export const authComponent = createClient<DataModel>(components.betterAuth)
export const createAuth = (ctx: GenericCtx<DataModel>) =>
betterAuth({
trustedOrigins: ['myapp://'], // must match app.json `scheme`
database: authComponent.adapter(ctx),
emailAndPassword: { enabled: true, requireEmailVerification: false },
plugins: [expo(), convex({ authConfig })],
})
export const getCurrentUser = query({
args: {},
handler: async (ctx) => authComponent.getAuthUser(ctx),
})
convex/http.tsimport { httpRouter } from 'convex/server'
import { authComponent, createAuth } from './auth'
const http = httpRouter()
authComponent.registerRoutes(http, createAuth)
export default http
Without this file there are no auth endpoints at all — everything else looks correct and nothing works.
src/lib/auth-client.tsimport { createAuthClient } from 'better-auth/react'
import { convexClient } from '@convex-dev/better-auth/client/plugins'
import { expoClient } from '@better-auth/expo/client'
import Constants from 'expo-constants'
import * as SecureStore from 'expo-secure-store'
export const authClient = createAuthClient({
baseURL: process.env.EXPO_PUBLIC_CONVEX_SITE_URL, // SITE origin
plugins: [
expoClient({
scheme: Constants.expoConfig?.scheme as string,
storagePrefix: Constants.expoConfig?.scheme as string,
storage: SecureStore,
}),
convexClient(),
],
})
expo-secure-store is the cookie store — the OS keychain/keystore, not AsyncStorage. Do not substitute AsyncStorage; session tokens would land in plaintext.
The as BetterAuthClientPlugin assertion on expoClient(...) is deliberate. With better-auth 1.6.x and @convex-dev/better-auth 0.12.x, the Expo plugin's inferred shape does not structurally satisfy BetterAuthClientPlugin, and without the assertion the error surfaces at ConvexBetterAuthProvider in _layout.tsx — far from its cause and very hard to read. Import the type from better-auth/client (not better-auth/react). This is upstream type friction, not a version skew: verify with npm ls better-auth @better-auth/core @better-auth/expo that there is exactly one copy of each at matching versions, and if so, leave the assertion. Retry removing it after a Better Auth bump.
convex devconvex/_generated/ does not exist until Convex codegen has run, and codegen requires a configured deployment — npx convex codegen fails with No CONVEX_DEPLOYMENT set. So on a fresh clone tsc reports "Cannot find module './_generated/api'" until someone runs npx convex dev once.
That means _generated cannot be committed-around or stubbed in CI without cost. Order CI as: provision/point at a deployment → npx convex codegen → tsc. Do not "fix" the errors by loosening types in convex/*.ts; they are correct and they disappear the moment codegen runs.
src/app/_layout.tsximport { ConvexReactClient } from 'convex/react'
import { ConvexBetterAuthProvider } from '@convex-dev/better-auth/react'
import { authClient } from '@/lib/auth-client'
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL!, {
expectAuth: true,
unsavedChangesWarning: false,
})
export default function RootLayout() {
return (
<ConvexBetterAuthProvider client={convex} authClient={authClient}>
{/* … */}
</ConvexBetterAuthProvider>
)
}
expectAuth: true makes the client wait for a token instead of firing unauthenticated queries on launch — without it you get a burst of failures on every cold start.
All routes always exist in Expo Router; access is a runtime concern. Use Stack.Protected with a guard:
const { data: session, isPending } = authClient.useSession()
<Stack>
<Stack.Protected guard={!!session}>
<Stack.Screen name="(app)" />
</Stack.Protected>
<Stack.Protected guard={!session}>
<Stack.Screen name="(auth)" />
</Stack.Protected>
</Stack>
Hold the splash screen until isPending resolves. Skipping that produces a visible flash of the sign-in screen for already-authenticated users on every launch — the cheapest quality bug to fix and the most noticeable.
A deep link into a protected route redirects to sign-in; preserve the intended destination and resume after auth. Presenting sign-in as a formSheet over the current screen keeps the destination on the stack for free — see expo-stack-ui-kit.
# cloud
npx convex dev # writes CONVEX_DEPLOYMENT
# self-hosted (.env.local)
CONVEX_SELF_HOSTED_URL=https://convex-api.example.com
CONVEX_SELF_HOSTED_ADMIN_KEY=…
# either way — server secrets go in Convex, not .env
npx convex env set BETTER_AUTH_SECRET="$(openssl rand -base64 32)"
Rules:
EXPO_PUBLIC_* is inlined into the client bundle. Anything else in .env is invisible to app code — and anything secret in an EXPO_PUBLIC_* var is shipped to every user's device.BETTER_AUTH_SECRET and OAuth client secrets belong in Convex env (convex env set), never in .env or app.config.ts.<site-origin>/api/auth/callback/<provider>.useQuery returns undefined while loading — not null, not an empty array. Handle it explicitly at every call site; treating it as "no data" renders an empty state during every load. See expo-stack-premium-ui.
const items = useQuery(api.items.list)
if (items === undefined) return <Skeleton />
if (items.length === 0) return <EmptyState />
templates/self-hosted/ ships a working Coolify compose. The parts that bite later:
convex-backend and convex-dashboard to the same image digest and upgrade them together. They are versioned as a pair, and a backend release can require SQL migrations against Postgres — migrate, then bump both.POSTGRES_URL carries no database name. Convex derives the database from INSTANCE_NAME with dashes converted to underscores. If the pre-created POSTGRES_DB does not match that transform, Convex quietly creates a second, empty database and your data appears to vanish.DO_NOT_REQUIRE_SSL=true is only valid on an internal Docker network. Never carry it to a managed or remote Postgres./convex/data/storage/exports or they accumulate after every run.convex-snapshot-exports, convex-snapshot-imports, convex-modules, convex-user-files, convex-search-indexes.Self-hosted covers the cloud product's free-tier feature set; the hosted product is what is optimised for scale.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
14 skills in this plugin
/expo-stackScaffold, configure, diagnose, polish, and ship production Expo applications with the Expo Stack workflow in Codex./expo-stack-architectureFolder layout, the routes-only rule, platform file extensions, and monorepo/workspace wiring for an Expo Router app in this stack. Use when scaffolding a project, deciding where a new file belongs, adding a shared package, or fixing Metro resolution in a bun/pnpm/yarn workspace./expo-stack-asoApp Store Optimization as part of the build loop — the indexed metadata fields, keyword strategy, screenshots that rank as well as convert, review-prompt timing, and store localization matched to the app's locales. Use when preparing a store listing, choosing a title/subtitle/keywords, planning screenshots, adding a rating prompt, or asked why an app is not being found./expo-stack-deep-linkingDeep linking in this stack — app scheme, Universal Links / App Links, the `+native-intent.tsx` rewrite hook, and deferred deep linking that survives an App Store install. Use when adding share/invite links, handling an OAuth or magic-link callback, wiring referrals or attribution, or debugging a link that opens the wrong screen, opens the store instead of the app, or gets swallowed by an auth or onboarding gate./expo-stack-i18nMulti-language support with react-i18next, i18next and expo-localization in an Expo Router app — typed locale files, device-language detection, a persisted user override, and RTL. Use when adding localisation, adding a language, changing how strings are organised, or when translations resolve to their key instead of text./expo-stack-monetizationRevenueCat in an Expo app — install and config plugin, per-platform keys, entitlement gating, paywall placement, and store-review requirements. Use when adding subscriptions or in-app purchases, gating a feature behind a paywall, or debugging purchases, restores and entitlements.npx claudepluginhub flyingwebie/skills --plugin expo-stackOther plugins' skills for the same job