auth

Add user accounts and sign-in to a TanStack Start app via Better Auth.

Updated Sep 17, 2026
One-click install
npx skills add https://github.com/scomofo/midi-stage2 --skill auth-scomofo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: auth
Source: https://github.com/scomofo/midi-stage2/tree/main/.grok/skills/auth
Command: npx skills add https://github.com/scomofo/midi-stage2 --skill auth-scomofo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, and includes references (resource) components.

What problem does it solve? Adding authentication to a TanStack Start app normally requires wiring OAuth providers, session handling, protected routes, and per-user data scoping from scratch. This Skill activates a pre-wired Better Auth setup that federates Google and X sign-in through the Grok broker, with optional local email/password accounts. ## Core Features & Use Cases - Broker-federated sign-in: Google and X OAuth through the Grok auth broker, plus optional email/password accounts persisted in the app's own database. - Pre-wired auth library: src/lib/auth/ ships with client helpers, React hooks, gate components (SignedIn, SignedOut, UserButton), and authMiddleware for scoping server functions to context.userId. - Zero-click gate identity: Deployed apps behind the Grok edge gate sign viewers in automatically from the x-grok-identity JWT, with popup-based sign-in as the live-preview fallback. - Use Case: A user asks to add login so each visitor sees only their own saved songs. The Skill flips VITE_AUTH_ENABLED, copies the auth migration, mounts the /api/auth/$ catch-all route and a login page, and wraps server functions in authMiddleware. ## Quick Start Add sign-in with Google and X to this app and protect the saved-songs server functions so each user only sees their own data.

Frequently Asked Questions about auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add sign-in to a TanStack Start app?▼

Remove the VITE_AUTH_ENABLED key from .grok/app-env.json, restart the dev server, copy migrations/auth/0001_auth.sql into migrations/, and add the /api/auth/$ catch-all route plus a login page. Then call signIn(providerId) from @/lib/auth/client.

What sign-in methods does Better Auth support here?▼

Only Google and X, federated through the Grok broker, plus optional local email/password accounts enabled in src/lib/auth/email-password.ts. No other OAuth providers, magic links, passkeys, OTP, or anonymous sign-in are supported.

How do I protect server functions with per-user data?▼

Wrap every server function touching per-user data in authMiddleware from @/lib/auth/middleware and scope all reads and writes to context.userId. Signed-out callers get an UnauthorizedError with status 401; never trust a client-supplied user id.

Why does the full app open inside the sign-in popup?▼

This happens when a React route is created at src/routes/auth/popup.tsx. The popup is already served by the template Vite plugin via popup.server.ts, so creating that route loads the app shell in the popup. Delete the route to fix it.

Why does sign-up return an Invalid origin error?▼

Better Auth rejects requests from origins outside trustedOrigins, which covers *.grok-sandbox.com and loopback on port 8082. Open the app at one of those origins instead of disabling CSRF or editing server.ts.

Can I add GitHub or Apple sign-in providers?▼

No. The Grok broker federates only Google and X and rejects unknown idp values, so do not add entries to GROK_PROVIDERS. Email/password is the only additional supported method.