Skip to content

Commit d1751a7

Browse files
authored
fix(init-prompt): require StackProvider for all frameworks (#1374)
## Summary - The init prompt marked the `StackProvider` step as *React only* and placed it after the `StackHandler` step. Following it on a Next.js project produced a layout with no provider, so `StackHandler` crashed at runtime with `useStackApp must be used within a StackProvider`. - Make the provider step unconditional and move it ahead of the handler step so the dependency order matches the instruction order. Also quote the exact error message so the model won't skip it. ## Test plan - [ ] Run `npx @stackframe/stack-cli init` (or the web flow) against a fresh Next.js app and confirm `/handler/[...stack]` renders without the `useStackApp` error. - [ ] Re-run against a Vite/React app to confirm the reordered instructions still produce a working setup. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added explicit global MCP config file path guidance for several coding agents. * Documented required provider configuration across supported frameworks. * Clarified where to place provider wrappers in root app layouts (including Next.js app/layout). * Reordered setup steps to surface the required "Wrap your app in a Stack provider" step and updated step numbering. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 4a2595d commit d1751a7

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

packages/stack-shared/src/helpers/init-prompt.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ These instructions describe how to set up Stack Auth.
88
${web ? `
99
First of all, if you have access to a terminal, it is better to use the \`npx @stackframe/stack-cli init\`` : ""}
1010
11-
Install mcp server from https://mcp.stack-auth.com if not already installed
11+
Install mcp server from https://mcp.stack-auth.com if not already installed. Global MCP config file paths for popular coding agents:
12+
- Claude Code: \`~/.claude.json\`
13+
- Codex CLI: \`~/.codex/config.toml\`
14+
- Cursor: \`~/.cursor/mcp.json\`
15+
- opencode: \`~/.config/opencode/opencode.json\`
1216
1317
For reference, questions, or information on Stack Auth, you can query the docs on https://docs.stack-auth.com via curl or any tools that you have
1418
@@ -65,7 +69,28 @@ export const stackServerApp = new StackServerApp({
6569
});
6670
\`\`\`
6771
68-
### 3) Create the Stack handler (if available in framework)
72+
### 3) Wrap your app in a Stack provider
73+
74+
Required for all React based frameworks (including Next.js). \`StackHandler\`, \`useUser\`, and \`useStackApp\` all depend on it — without it you will get "useStackApp must be used within a StackProvider" at runtime. In Next.js, add it to the root \`app/layout.tsx\` around \`{children}\`. In React/Vite, wrap your root component.
75+
76+
\`\`\`tsx
77+
import { StackProvider, StackTheme } from "@stackframe/stack"; // or "@stackframe/react"
78+
import { stackClientApp } from "../stack/client"; // adjust relative path
79+
\`\`\`
80+
81+
Then wrap the body content:
82+
83+
\`\`\`tsx
84+
return (
85+
<body>
86+
<StackProvider app={stackClientApp}>
87+
<StackTheme>{children}</StackTheme>
88+
</StackProvider>
89+
</body>
90+
);
91+
\`\`\`
92+
93+
### 4) Create the Stack handler (if available in framework)
6994
7095
This sets up pages for sign in, sign up, password reset, etc.
7196
@@ -78,7 +103,7 @@ export default function Handler() {
78103
}
79104
\`\`\`
80105
81-
### 4) Create a Suspense boundary
106+
### 5) Create a Suspense boundary
82107
83108
Suspense is necessary for many stack auth hooks such as useUser to function. Add a loading component with a custom loading indicator for the current project. Don't add if one already exists
84109
@@ -91,7 +116,7 @@ export default function Loading() {
91116
}
92117
\`\`\`
93118
94-
### 5) Link environment variables
119+
### 6) Link environment variables
95120
96121
This is only necessary if not using local emulator. Ensure these are ignored by git.
97122
@@ -103,24 +128,4 @@ The required variables are:
103128
104129
The publishable client key (e.g. NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY, VITE_STACK_PUBLISHABLE_CLIENT_KEY, etc.) is only required if your project has publishable client keys enabled as a requirement.
105130
106-
### 6) React only: Wrap the entire page in a Stack provider
107-
108-
This is used for the useUser and useStackApp hooks.
109-
110-
\`\`\`tsx
111-
import { StackProvider, StackTheme } from "@stackframe/stack";
112-
import { stackClientApp } from "../stack/client"; // adjust relative path
113-
\`\`\`
114-
115-
Then wrap the body content:
116-
117-
\`\`\`tsx
118-
return (
119-
<body>
120-
<StackProvider app={stackClientApp}>
121-
<StackTheme>{children}</StackTheme>
122-
</StackProvider>
123-
</body>
124-
);
125-
\`\`\`
126131
`;

0 commit comments

Comments
 (0)