stack/examples/tanstack-start-demo/src/stack.ts
Mantra 68ae6d1f1c
[codex] Add TanStack Start SDK integration (#1399)
## Summary

- Adds the generated `@stackframe/tanstack-start` workspace package
registration.
- Adds TanStack Start platform macros/dependencies to the SDK template
and generator.
- Adds TanStack Start cookie/token-store support plus the handler SSR
guard needed by Start.

## Scope

This intentionally excludes Dashboard V2 routes, hooks, components, app
shell logic, and dashboard API type additions. Those stay in the
existing dashboard PR/branch.

## Validation

- `pnpm install --lockfile-only --ignore-scripts`
- `pnpm install --ignore-scripts`
- `pnpm -C packages/template lint
src/components-page/stack-handler-client.tsx src/lib/cookie.ts
src/lib/stack-app/apps/implementations/client-app-impl.ts`

Package typecheck was attempted with `pnpm -C packages/template
typecheck`, but the clean worktree lacks generated package declaration
outputs for workspace dependencies such as `@stackframe/stack-shared`
and `@stackframe/stack-ui`. Per repo instructions, package
builds/codegen are not run by agents.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* TanStack Start integration: published SDK package, example demo app,
dashboard onboarding flow, framework-aware CTAs/docs, and a
TanStack-specific provider for client-only auth routes.
* Improved client/server auth: safer runtime guards and consistent
cookie/token-store behavior across SSR and client.

* **Documentation**
* New Integrations guide and expanded getting-started/setup docs with
TanStack Start examples and env/key guidance.

* **Chores**
* Template, build, tooling, and demo config updates to support the new
platform.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-08 10:59:16 -07:00

30 lines
1005 B
TypeScript

import { StackClientApp } from "@stackframe/tanstack-start";
function getPortPrefix(): string {
return import.meta.env.NEXT_PUBLIC_STACK_PORT_PREFIX ?? "81";
}
function replaceStackPortPrefix(value: string): string {
return value.replace(/\$\{NEXT_PUBLIC_STACK_PORT_PREFIX:-81\}/g, getPortPrefix());
}
function getStackApiUrl(): string {
const configured = import.meta.env.VITE_STACK_API_URL as string | undefined;
return configured ? replaceStackPortPrefix(configured) : `http://localhost:${getPortPrefix()}02`;
}
export function createStackApp() {
return new StackClientApp({
projectId: import.meta.env.VITE_STACK_PROJECT_ID ?? "internal",
publishableClientKey: import.meta.env.VITE_STACK_PUBLISHABLE_CLIENT_KEY ?? "this-publishable-client-key-is-for-local-development-only",
baseUrl: getStackApiUrl(),
tokenStore: "cookie",
redirectMethod: "window",
urls: {
afterSignIn: "/protected",
afterSignUp: "/protected",
afterSignOut: "/",
},
});
}