mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-30 21:01:54 +08:00
## Summary
Follow-up from analyzing the dogfooding report on the `ask_hexclave` MCP
tool. Two root causes were confirmed against source:
1. **The "`STACK_` vs `HEXCLAVE_` env var hallucination" wasn't a
hallucination** — it's an incomplete Stack Auth → Hexclave rebrand. The
SDK resolves both prefixes (`packages/js/src/generated/env.ts`), with
`HEXCLAVE_*` canonical and `STACK_*` a legacy fallback, but several
docs/examples still showed the old `STACK_*` names. That inconsistency
is what misled agents into thinking `HEXCLAVE_*` was made up.
2. **`ask_hexclave` timeouts** — the tool proxies to a `quality:
"smart"` agentic docs-search loop. The agent step budget (50) and the
120s timeouts were too tight; broad/multi-part questions blew the budget
(reproduced 3× while investigating).
## Changes
### Docs: canonicalize client SDK auth env vars to `HEXCLAVE_*`
Converted `PROJECT_ID`, `PUBLISHABLE_CLIENT_KEY`, `SECRET_SERVER_KEY`,
`API_URL` (+ `NEXT_PUBLIC_` / `VITE_` forms) from `STACK_*` →
`HEXCLAVE_*` in app-setup docs + the package template:
-
`docs-mintlify/guides/integrations/{convex,tanstack-start,vercel}/overview.mdx`
- `docs-mintlify/guides/going-further/local-vs-cloud-dashboard.mdx`
- `docs-mintlify/guides/apps/analytics/overview.mdx`
- `docs-mintlify/guides/other/tutorials/ship-production-ready-auth.mdx`
- `docs-mintlify/sdk/objects/hexclave-app.mdx`
- `packages/template/src/integrations/convex/component/README.md` (the
tracked source of the generated `@hexclave/js` + `@hexclave/next` copies
— the generated copies are git-ignored)
**Deliberately left untouched** — read literally by the backend/CLI (no
`HEXCLAVE_` alias) or user-defined: `STACK_CLICKHOUSE_*`,
`STACK_DATABASE_*`, `STACK_OPENROUTER_*`, `STACK_CLI_*`, `STACK_SEED_*`,
`STACK_WEBHOOK_SECRET`, `STACK_DATA_VAULT_SECRET`, and the `x-stack-*`
HTTP headers. So `self-host.mdx`, `cli.mdx`, `jwts.mdx`, `webhooks`, and
`data-vault` docs are intentionally unchanged.
### Reliability: raise `ask_hexclave` step limit + timeout
- `apps/backend/src/app/api/latest/ai/query/[mode]/route.ts`:
docs/search agent step limit **50 → 75** (+50%); AI generation abort
**120s → 180s**
- `apps/mcp/src/mcp-handler.ts`: MCP function `maxDuration` **120 →
180** (kept ≥ backend timeout so the proxy doesn't die before the
backend finishes)
## Notes
- Also includes a small pre-existing `run pnpm fml` commit (regenerated
docs snippets / `llms-full.txt`).
- The step/timeout bumps address the *symptom*. The durable reliability
fix is streaming/keepalive on the MCP proxy so the client never idles
out mid-query — proposed as a follow-up.
- **Not** included: the separate `sendEmail` doc-vs-SDK drift (docs
declare `Promise<Result<void, KnownErrors>>` in
`sdk/objects/hexclave-app.mdx`, but the SDK returns `Promise<void>` and
throws). That's a docs *correctness* bug deserving its own PR.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Canonicalized auth env vars in docs/templates to `HEXCLAVE_*`, raised
docs/search step limits and timeouts, and clarified `HexclaveApp`
defaults. MCP tool and server instructions now require loading the
`skill` resource before queries.
- **Bug Fixes**
- Docs: Use `HEXCLAVE_PROJECT_ID`, `HEXCLAVE_PUBLISHABLE_CLIENT_KEY`,
`HEXCLAVE_SECRET_SERVER_KEY`, and optional `HEXCLAVE_API_URL` across
guides/templates (Vercel, Convex, TanStack Start, analytics). In SDK
docs, `secretServerKey` defaults to `HEXCLAVE_SECRET_SERVER_KEY`, and
client defaults use `NEXT_PUBLIC_HEXCLAVE_*`. Backend-only `STACK_*`
vars (`STACK_CLICKHOUSE_*`, `STACK_DATABASE_*`, `STACK_OPENROUTER_*`,
CLI/data-vault/webhook headers) unchanged.
- Reliability: Increase docs/search step limit 50→75 and timeouts
120s→180s; set MCP `maxDuration` to 180s; use `performance.now()` for
duration logging. MCP instructions updated to require loading the
`skill` resource before using tools.
<sup>Written for commit f6be2c3162.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/1571?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Performance & Reliability**
* Increased AI operation timeouts and step limits for certain prompts;
improved generate-mode duration measurement for more accurate logging.
* **Documentation**
* Replaced Stack-branded environment variable names with Hexclave
equivalents across guides and examples.
* Clarified that hexclave dev injects required environment variables
automatically.
* Added guidance on configuring custom authentication redirect URLs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
167 lines
5.2 KiB
Plaintext
167 lines
5.2 KiB
Plaintext
---
|
|
title: TanStack Start
|
|
description: Add Hexclave to a TanStack Start app.
|
|
---
|
|
|
|
<Info>
|
|
The `@hexclave/tanstack-start` package is currently alpha. Pin exact package versions before shipping production apps.
|
|
</Info>
|
|
|
|
TanStack Start is a full-stack React framework built on TanStack Router and Vite. Hexclave's TanStack Start package provides the same auth components and hooks as the React SDK, with cookie handling wired for TanStack Start.
|
|
|
|
## Setup
|
|
|
|
<Steps>
|
|
<Step title="Create or open a TanStack Start app">
|
|
If you do not have a TanStack Start app yet, create one with the TanStack CLI:
|
|
|
|
```bash title="Terminal"
|
|
npx @tanstack/cli@latest create
|
|
```
|
|
|
|
TanStack also publishes official examples if you prefer to start from a working project.
|
|
</Step>
|
|
|
|
<Step title="Install Hexclave">
|
|
Install the alpha TanStack Start package:
|
|
|
|
```bash title="Terminal"
|
|
npm install @hexclave/tanstack-start
|
|
```
|
|
</Step>
|
|
|
|
<Step title="Create Hexclave keys">
|
|
In the [Hexclave dashboard](https://app.hexclave.com/projects), create a project and add these variables to your TanStack Start environment:
|
|
|
|
```bash title=".env"
|
|
VITE_HEXCLAVE_PROJECT_ID=<your-project-id>
|
|
HEXCLAVE_SECRET_SERVER_KEY=<your-secret-server-key>
|
|
```
|
|
|
|
Keep `HEXCLAVE_SECRET_SERVER_KEY` server-only. Do not expose it to client code.
|
|
</Step>
|
|
|
|
<Step title="Create a Stack client app">
|
|
Create a Stack client app with cookie storage:
|
|
|
|
```ts title="src/stack/client.ts"
|
|
import { HexclaveClientApp } from "@hexclave/tanstack-start";
|
|
|
|
export const hexclaveClientApp = new HexclaveClientApp({
|
|
projectId: import.meta.env.VITE_HEXCLAVE_PROJECT_ID,
|
|
tokenStore: "cookie",
|
|
redirectMethod: "window",
|
|
});
|
|
```
|
|
</Step>
|
|
|
|
<Step title="Wrap the root route">
|
|
Add `HexclaveProvider` and `HexclaveTheme` around your route outlet:
|
|
|
|
```tsx title="src/routes/__root.tsx"
|
|
import { HexclaveProvider, HexclaveTheme } from "@hexclave/tanstack-start";
|
|
import { createRootRoute, HeadContent, Outlet, Scripts } from "@tanstack/react-router";
|
|
import { hexclaveClientApp } from "../stack/client";
|
|
|
|
export const Route = createRootRoute({
|
|
component: RootComponent,
|
|
shellComponent: RootDocument,
|
|
});
|
|
|
|
function RootComponent() {
|
|
return (
|
|
<HexclaveProvider app={hexclaveClientApp}>
|
|
<HexclaveTheme>
|
|
<Outlet />
|
|
</HexclaveTheme>
|
|
</HexclaveProvider>
|
|
);
|
|
}
|
|
|
|
function RootDocument({ children }: { children: React.ReactNode }) {
|
|
return (
|
|
<html>
|
|
<head>
|
|
<HeadContent />
|
|
</head>
|
|
<body>
|
|
{children}
|
|
<Scripts />
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|
|
```
|
|
</Step>
|
|
|
|
<Step title="Add the auth handler route">
|
|
Create a splat route at `/handler/*` for Hexclave's built-in pages:
|
|
|
|
```tsx title="src/routes/handler/$.tsx"
|
|
import { HexclaveHandler } from "@hexclave/tanstack-start";
|
|
import { createFileRoute, useLocation } from "@tanstack/react-router";
|
|
|
|
export const Route = createFileRoute("/handler/$")({
|
|
ssr: false,
|
|
component: HandlerPage,
|
|
});
|
|
|
|
function HandlerPage() {
|
|
const { pathname } = useLocation();
|
|
return <HexclaveHandler fullPage location={pathname} />;
|
|
}
|
|
```
|
|
</Step>
|
|
|
|
<Step title="Use auth in routes">
|
|
Use Stack hooks from inside components rendered under the provider:
|
|
|
|
```tsx title="src/routes/index.tsx"
|
|
import { useUser } from "@hexclave/tanstack-start";
|
|
import { createFileRoute, Link } from "@tanstack/react-router";
|
|
|
|
export const Route = createFileRoute("/")({
|
|
component: HomePage,
|
|
});
|
|
|
|
function HomePage() {
|
|
const user = useUser();
|
|
|
|
if (!user) {
|
|
return <Link to="/handler/sign-in">Sign in</Link>;
|
|
}
|
|
|
|
return <div>Signed in as {user.primaryEmail}</div>;
|
|
}
|
|
```
|
|
|
|
Routes that use browser redirects should render on the client:
|
|
|
|
```tsx title="src/routes/protected.tsx"
|
|
import { useUser } from "@hexclave/tanstack-start";
|
|
import { createFileRoute } from "@tanstack/react-router";
|
|
|
|
export const Route = createFileRoute("/protected")({
|
|
ssr: false,
|
|
component: ProtectedPage,
|
|
});
|
|
|
|
function ProtectedPage() {
|
|
const user = useUser({ or: "redirect" });
|
|
return <div>Welcome, {user.primaryEmail}</div>;
|
|
}
|
|
```
|
|
</Step>
|
|
</Steps>
|
|
|
|
## Notes
|
|
|
|
- The handler route must stay under the same origin as your app when using `tokenStore: "cookie"`.
|
|
- Render the handler route on the client (`ssr: false`) because built-in auth pages read browser location state.
|
|
- Render routes that rely on `useUser({ or: "redirect" })` on the client (`ssr: false`) when using `redirectMethod: "window"`.
|
|
- Use `redirectMethod: "window"` unless you explicitly wire a TanStack Router navigation adapter.
|
|
- If you change auth routes, configure the matching `urls` on `HexclaveClientApp`.
|
|
- For server-only logic, use TanStack Start server functions and keep `HEXCLAVE_SECRET_SERVER_KEY` out of client modules.
|
|
|
|
For TanStack Start framework details, see the [TanStack Start quick start](https://tanstack.com/start/latest/docs/framework/react/quick-start) and [server functions guide](https://tanstack.com/start/latest/docs/framework/react/guide/server-functions).
|