Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/templates/others/convex.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default {
Then, update your Convex client to use Stack Auth:

```ts
convexClient.setAuth(stackServerApp.getConvexClientAuth({})); // browser JS
convexReactClient.setAuth(stackServerApp.getConvexClientAuth({})); // React
convexHttpClient.setAuth(stackServerApp.getAuthForConvexHttpClient({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
convexClient.setAuth(stackClientApp.getConvexClientAuth({})); // browser JS
convexReactClient.setAuth(stackClientApp.getConvexClientAuth({})); // React
convexHttpClient.setAuth(stackClientApp.getConvexHttpClientAuth({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
```

### 5) Done!
Expand All @@ -77,4 +77,5 @@ export const myQuery = query({
});
```

For more information on how to use Stack Auth, see the [Stack Auth docs](https://docs.stack-auth.com).
You can find the full example [here on GitHub](https://github.com/stack-auth/convex-next-template).

6 changes: 3 additions & 3 deletions packages/template/src/integrations/convex/component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export default {
Then, update your Convex client to use Stack Auth:

```ts
convexClient.setAuth(stackServerApp.getConvexClientAuth()); // browser JS
convexReactClient.setAuth(stackServerApp.getConvexClientAuth()); // React
convexHttpClient.setAuth(stackServerApp.getAuthForConvexHttpClient({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
convexClient.setAuth(stackClientApp.getConvexClientAuth({})); // browser JS
convexReactClient.setAuth(stackClientApp.getConvexClientAuth({})); // React
convexHttpClient.setAuth(stackClientApp.getConvexHttpClientAuth({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Confirm HTTP context: client vs server app for Convex HTTP.

If convexHttpClient runs on the server and needs a request-backed token store, you likely want the server app variant. If it’s intentionally used in a client-like environment with an explicit token store, current line is fine. Please verify.

Suggested server-side alternative (note updated method name):

-convexHttpClient.setAuth(stackClientApp.getConvexHttpClientAuth({ tokenStore: requestObject }));  // HTTP, see Stack Auth docs for more information on tokenStore
+convexHttpClient.setAuth(stackServerApp.getConvexHttpClientAuth({ tokenStore: requestObject }));  // HTTP (server), tokenStore built from the request

Run to verify API surface and find stale references:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Check where getConvexHttpClientAuth is defined/used:"
rg -n -C2 --type=ts 'getConvexHttpClientAuth\s*\(' || true

echo "Check whether both client and server apps expose it (interfaces/classes):"
rg -n -C3 --type=ts 'interface .*Client.*\{[^}]*getConvexHttpClientAuth' || true
rg -n -C3 --type=ts 'interface .*Server.*\{[^}]*getConvexHttpClientAuth' || true
rg -n -C3 --type=ts 'class .*Client.*\{[^}]*getConvexHttpClientAuth' || true
rg -n -C3 --type=ts 'class .*Server.*\{[^}]*getConvexHttpClientAuth' || true

echo "Find any stale method name:"
rg -n -C2 'getAuthForConvexHttpClient' || true

Length of output: 1829


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files under packages/template/src/lib/stack-app/apps:"
find packages/template/src/lib/stack-app/apps -type f

Length of output: 660


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Inspect server-app interface for getConvex methods:"
rg -n --type=ts 'getConvex' -C3 packages/template/src/lib/stack-app/apps/interfaces/server-app.ts || true

echo "Inspect server-app implementation for getConvex methods:"
rg -n --type=ts 'getConvex' -C3 packages/template/src/lib/stack-app/apps/implementations/server-app-impl.ts || true

Length of output: 108


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== server-app interface ==="
sed -n '1,200p' packages/template/src/lib/stack-app/apps/interfaces/server-app.ts

echo "=== server-app implementation ==="
sed -n '1,200p' packages/template/src/lib/stack-app/apps/implementations/server-app-impl.ts

Length of output: 17420


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== README context lines 1-100 ==="
sed -n '1,100p' packages/template/src/integrations/convex/component/README.md || true

Length of output: 2075


Use StackServerApp for HTTP auth

Replace the client-app call with the server-app variant so you generate tokens with your secret key:

-convexHttpClient.setAuth(stackClientApp.getConvexHttpClientAuth({ tokenStore: requestObject }));
+convexHttpClient.setAuth(stackServerApp.getConvexHttpClientAuth({ tokenStore: requestObject }));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
convexHttpClient.setAuth(stackClientApp.getConvexHttpClientAuth({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
convexHttpClient.setAuth(stackServerApp.getConvexHttpClientAuth({ tokenStore: requestObject })); // HTTP, see Stack Auth docs for more information on tokenStore
🤖 Prompt for AI Agents
packages/template/src/integrations/convex/component/README.md around line 36:
the example uses the client-app method to set HTTP auth which does not generate
tokens with the server secret; replace the call to use the server-app variant
(StackServerApp) so tokens are created with your secret key by invoking the
server-app getConvexHttpClientAuth and passing the same
tokenStore/requestObject.

```

Now, you'll be able to access Stack Auth's functionality from your frontend & backend:
Expand Down