Skip to content

Commit 3efb226

Browse files
authored
make publishable client keys truly optional ig (i hope) (#1274)
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Documentation * Updated setup instructions across all documentation to clarify that the publishable client key is only required when your project configuration enforces it, removing confusion about unconditional requirements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 736c1a1 commit 3efb226

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

docs/content/docs/(guides)/concepts/stack-app.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function ClientComponent() {
3939

4040
## Client vs. server
4141

42-
`StackClientApp` contains everything needed to build a frontend application, for example the currently authenticated user. It requires a publishable client key in its initialization (usually set by the `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY` environment variable).
42+
`StackClientApp` contains everything needed to build a frontend application, for example the currently authenticated user. It can use a publishable client key in its initialization (usually set by the `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY` environment variable), but that key is only required if the project is configured to require publishable client keys.
4343

4444
`StackServerApp` has all the functionality of `StackClientApp`, but also some functions with elevated permissions, eg. listing or modifying ALL users. This requires a secret server key (usually set by the `STACK_SECRET_SERVER_KEY` environment variable), which **must always be kept secret**.
4545

docs/content/docs/(guides)/getting-started/setup.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ We recommend using our **setup wizard** for JavaScript frameworks for a seamless
4040
### Update API keys
4141
</Step>
4242

43-
Create an account on [the Stack Auth dashboard](https://app.stack-auth.com/projects), create a new project with an API key, and copy its environment variables into the appropriate configuration file:
43+
Create an account on [the Stack Auth dashboard](https://app.stack-auth.com/projects), create a new project, and copy its environment variables into the appropriate configuration file. If your project requires publishable client keys, create a project key that includes one and copy that as well.
4444

4545
<PlatformCodeblock
4646
document="setup/setup"
@@ -91,7 +91,7 @@ We recommend using our **setup wizard** for JavaScript frameworks for a seamless
9191
### Create API keys
9292
</Step>
9393

94-
[Register a new account on Stack](https://app.stack-auth.com/handler/sign-up), create a project in the dashboard, create a new API key from the left sidebar, and copy the project ID, publishable client key, and secret server key.
94+
[Register a new account on Stack](https://app.stack-auth.com/handler/sign-up), create a project in the dashboard, and copy the project ID. If your project requires publishable client keys, also create a project key from the left sidebar and copy the publishable client key. For server-side setups, also copy the secret server key.
9595

9696
<Step>
9797
### Configure environment variables

docs/src/app/api/internal/[transport]/setup-instructions.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ Ensure they are added to the repo.
4646
#### For Next.js Projects:
4747
Required vars (from Stack dashboard):
4848
- `NEXT_PUBLIC_STACK_PROJECT_ID`
49-
- `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY`
5049
- `STACK_SECRET_SERVER_KEY`
5150

51+
Optional unless your project requires publishable client keys:
52+
- `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY`
53+
5254
Check `.env.local`:
5355
- If the file is unreadable (ignored or access denied), DO NOT assume it's configured.
5456
- If any required var is missing or empty, prompt the user and PAUSE.
@@ -64,7 +66,8 @@ import { StackClientApp } from "@stackframe/react";
6466
export const stackClientApp = new StackClientApp({
6567
// You should store these in environment variables
6668
projectId: "YOUR_PROJECT_ID_HERE",
67-
publishableClientKey: "YOUR_PUBLISHABLE_CLIENT_KEY_HERE",
69+
// Only include this if your project requires publishable client keys
70+
// publishableClientKey: "YOUR_PUBLISHABLE_CLIENT_KEY_HERE",
6871
tokenStore: "cookie",
6972
// redirectMethod: {
7073
// useNavigate,
@@ -86,8 +89,8 @@ TODO in your web browser:
8689
3) Choose your framework: Next.js
8790
4) Copy these keys:
8891
- NEXT_PUBLIC_STACK_PROJECT_ID=...
89-
- NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=...
9092
- STACK_SECRET_SERVER_KEY=...
93+
- NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=... (only if your project requires publishable client keys)
9194
5) Paste them into your local `.env.local` (do not commit this file).
9295
6) Save the file.
9396
@@ -105,10 +108,10 @@ TODO in your web browser:
105108
3) Choose your framework: React
106109
4) Copy these keys:
107110
- Project ID
108-
- Publishable Client Key
111+
- Publishable Client Key (only if your project requires publishable client keys)
109112
5) Update the `stack/client.ts` file with your keys:
110113
- Replace "YOUR_PROJECT_ID_HERE" with your Project ID
111-
- Replace "YOUR_PUBLISHABLE_CLIENT_KEY_HERE" with your Publishable Client Key
114+
- If needed, uncomment and replace "YOUR_PUBLISHABLE_CLIENT_KEY_HERE" with your Publishable Client Key
112115
6) Save the file.
113116
114117
Reply here when done:
@@ -188,4 +191,3 @@ Reply with 1 or 2:
188191
189192
If user replies `1`: Proceed to UI Installation Workflow calling the tool install UI components.
190193
If user replies `2`: Explain to the user what Stack Auth can do for him by reading our documentation using the MCP
191-

packages/stack-cli/src/lib/init-prompt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Depending on whether you're on a client or a server, you will want to create sta
3131
The stack client app has client-level permissions. It contains most of the useful methods and hooks for your client-side code.
3232
The stack server app has full read and write access to all users. It requires STACK_SECRET_SERVER_KEY env variable and should only be used in secure context
3333
34-
In Next.js, env vars are auto-detected (NEXT_PUBLIC_STACK_PROJECT_ID etc.), so the constructor needs no explicit config. For other frameworks, you must pass projectId and publishableClientKey explicitly using the framework's env var access method.
34+
In Next.js, env vars are auto-detected (NEXT_PUBLIC_STACK_PROJECT_ID etc.), so the constructor needs no explicit config. For other frameworks, you must pass projectId explicitly using the framework's env var access method. Pass publishableClientKey only if your project is configured to require publishable client keys.
3535
3636
The tokenStore should be "nextjs-cookie" for Next.js, or "cookie" for all other frameworks.
3737
@@ -44,7 +44,7 @@ import { StackClientApp } from "@stackframe/stack"; // or "@stackframe/react" or
4444
4545
export const stackClientApp = new StackClientApp({
4646
// Next.js: omit projectId/publishableClientKey (auto-detected from NEXT_PUBLIC_ env vars)
47-
// Other frameworks: pass explicitly, e.g. for Vite:
47+
// Other frameworks: pass projectId explicitly, and publishableClientKey only if required by your project. For Vite:
4848
// projectId: import.meta.env.VITE_STACK_PROJECT_ID,
4949
// publishableClientKey: import.meta.env.VITE_STACK_PUBLISHABLE_CLIENT_KEY,
5050
tokenStore: "nextjs-cookie", // or "cookie" for non-Next.js,
@@ -99,9 +99,10 @@ Rename the env var keys in .env to match the framework's convention for client-e
9999
100100
The required variables are:
101101
- Project ID (e.g. NEXT_PUBLIC_STACK_PROJECT_ID, VITE_STACK_PROJECT_ID, etc.)
102-
- Publishable client key (e.g. NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY, VITE_STACK_PUBLISHABLE_CLIENT_KEY, etc.)
103102
- Secret server key: STACK_SECRET_SERVER_KEY (only for frameworks with server-side support, no prefix needed)
104103
104+
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.
105+
105106
### 6) React only: Wrap the entire page in a Stack provider
106107
107108
This is used for the useUser and useStackApp hooks.
@@ -123,4 +124,3 @@ return (
123124
);
124125
\`\`\`
125126
`;
126-

0 commit comments

Comments
 (0)