opencastle 0.33.9 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +39 -17
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/stack-config.d.ts.map +1 -1
- package/dist/cli/stack-config.js +5 -0
- package/dist/cli/stack-config.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/orchestrator/plugins/cloudflare/config.d.ts +3 -0
- package/dist/orchestrator/plugins/cloudflare/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/cloudflare/config.js +23 -0
- package/dist/orchestrator/plugins/cloudflare/config.js.map +1 -0
- package/dist/orchestrator/plugins/coolify/config.d.ts +3 -0
- package/dist/orchestrator/plugins/coolify/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/coolify/config.js +28 -0
- package/dist/orchestrator/plugins/coolify/config.js.map +1 -0
- package/dist/orchestrator/plugins/drizzle/config.d.ts +3 -0
- package/dist/orchestrator/plugins/drizzle/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/drizzle/config.js +15 -0
- package/dist/orchestrator/plugins/drizzle/config.js.map +1 -0
- package/dist/orchestrator/plugins/expo/config.d.ts +3 -0
- package/dist/orchestrator/plugins/expo/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/expo/config.js +23 -0
- package/dist/orchestrator/plugins/expo/config.js.map +1 -0
- package/dist/orchestrator/plugins/index.d.ts.map +1 -1
- package/dist/orchestrator/plugins/index.js +12 -0
- package/dist/orchestrator/plugins/index.js.map +1 -1
- package/dist/orchestrator/plugins/sentry/config.d.ts +3 -0
- package/dist/orchestrator/plugins/sentry/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/sentry/config.js +28 -0
- package/dist/orchestrator/plugins/sentry/config.js.map +1 -0
- package/dist/orchestrator/plugins/stripe/config.d.ts +3 -0
- package/dist/orchestrator/plugins/stripe/config.d.ts.map +1 -0
- package/dist/orchestrator/plugins/stripe/config.js +42 -0
- package/dist/orchestrator/plugins/stripe/config.js.map +1 -0
- package/dist/orchestrator/plugins/types.d.ts +1 -1
- package/dist/orchestrator/plugins/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/init.ts +43 -22
- package/src/cli/stack-config.ts +5 -0
- package/src/cli/types.ts +1 -1
- package/src/dashboard/dist/data/convoys/demo-api-v2.json +3 -3
- package/src/dashboard/dist/data/convoys/demo-auth-revamp.json +4 -4
- package/src/dashboard/dist/data/convoys/demo-dashboard-ui.json +12 -12
- package/src/dashboard/dist/data/convoys/demo-data-pipeline.json +3 -3
- package/src/dashboard/dist/data/convoys/demo-deploy-ci.json +1 -1
- package/src/dashboard/dist/data/convoys/demo-docs-update.json +3 -3
- package/src/dashboard/dist/data/convoys/demo-perf-opt.json +4 -4
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/dashboard/public/data/convoys/demo-api-v2.json +3 -3
- package/src/dashboard/public/data/convoys/demo-auth-revamp.json +4 -4
- package/src/dashboard/public/data/convoys/demo-dashboard-ui.json +12 -12
- package/src/dashboard/public/data/convoys/demo-data-pipeline.json +3 -3
- package/src/dashboard/public/data/convoys/demo-deploy-ci.json +1 -1
- package/src/dashboard/public/data/convoys/demo-docs-update.json +3 -3
- package/src/dashboard/public/data/convoys/demo-perf-opt.json +4 -4
- package/src/orchestrator/customizations/agents/skill-matrix.json +24 -4
- package/src/orchestrator/customizations/agents/skill-matrix.md +5 -0
- package/src/orchestrator/plugins/cloudflare/SKILL.md +111 -0
- package/src/orchestrator/plugins/cloudflare/config.ts +24 -0
- package/src/orchestrator/plugins/cloudflare/references/deployment.md +147 -0
- package/src/orchestrator/plugins/cloudflare/references/storage.md +118 -0
- package/src/orchestrator/plugins/cloudflare/references/workers.md +135 -0
- package/src/orchestrator/plugins/convex/SKILL.md +62 -20
- package/src/orchestrator/plugins/convex/references/auth-auth0.md +116 -0
- package/src/orchestrator/plugins/convex/references/auth-clerk.md +113 -0
- package/src/orchestrator/plugins/convex/references/auth-convex-auth.md +143 -0
- package/src/orchestrator/plugins/convex/references/auth-setup.md +87 -0
- package/src/orchestrator/plugins/convex/references/auth-workos.md +114 -0
- package/src/orchestrator/plugins/convex/references/components-advanced.md +134 -0
- package/src/orchestrator/plugins/convex/references/components.md +171 -0
- package/src/orchestrator/plugins/convex/references/function-budget.md +232 -0
- package/src/orchestrator/plugins/convex/references/hot-path-rules.md +371 -0
- package/src/orchestrator/plugins/convex/references/migrations-component.md +170 -0
- package/src/orchestrator/plugins/convex/references/migrations.md +259 -0
- package/src/orchestrator/plugins/convex/references/occ-conflicts.md +126 -0
- package/src/orchestrator/plugins/convex/references/performance-audit.md +80 -0
- package/src/orchestrator/plugins/convex/references/quickstart.md +176 -0
- package/src/orchestrator/plugins/convex/references/subscription-cost.md +252 -0
- package/src/orchestrator/plugins/coolify/SKILL.md +134 -0
- package/src/orchestrator/plugins/coolify/config.ts +29 -0
- package/src/orchestrator/plugins/coolify/references/applications.md +65 -0
- package/src/orchestrator/plugins/coolify/references/ci-cd-webhooks.md +73 -0
- package/src/orchestrator/plugins/coolify/references/databases-services.md +57 -0
- package/src/orchestrator/plugins/coolify/references/docker-compose.md +121 -0
- package/src/orchestrator/plugins/coolify/references/infrastructure.md +77 -0
- package/src/orchestrator/plugins/drizzle/SKILL.md +123 -0
- package/src/orchestrator/plugins/drizzle/config.ts +16 -0
- package/src/orchestrator/plugins/drizzle/references/migrations.md +112 -0
- package/src/orchestrator/plugins/drizzle/references/query-patterns.md +127 -0
- package/src/orchestrator/plugins/drizzle/references/schema-patterns.md +105 -0
- package/src/orchestrator/plugins/expo/SKILL.md +114 -0
- package/src/orchestrator/plugins/expo/config.ts +24 -0
- package/src/orchestrator/plugins/expo/references/eas-build.md +73 -0
- package/src/orchestrator/plugins/expo/references/native-modules.md +71 -0
- package/src/orchestrator/plugins/expo/references/routing.md +83 -0
- package/src/orchestrator/plugins/index.ts +12 -0
- package/src/orchestrator/plugins/linear/SKILL.md +21 -3
- package/src/orchestrator/plugins/sentry/SKILL.md +94 -0
- package/src/orchestrator/plugins/sentry/config.ts +29 -0
- package/src/orchestrator/plugins/sentry/references/error-patterns.md +112 -0
- package/src/orchestrator/plugins/sentry/references/performance.md +66 -0
- package/src/orchestrator/plugins/sentry/references/sdk-setup.md +108 -0
- package/src/orchestrator/plugins/stripe/SKILL.md +138 -0
- package/src/orchestrator/plugins/stripe/config.ts +43 -0
- package/src/orchestrator/plugins/stripe/references/api-patterns.md +57 -0
- package/src/orchestrator/plugins/stripe/references/projects-setup.md +30 -0
- package/src/orchestrator/plugins/stripe/references/upgrade-guide.md +105 -0
- package/src/orchestrator/plugins/types.ts +1 -1
- package/src/orchestrator/skills/backbone-scaffolding/EXAMPLES.md +1 -1
- package/src/orchestrator/skills/backbone-scaffolding/SKILL.md +32 -16
- package/src/orchestrator/plugins/convex/REFERENCE.md +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: convex-database
|
|
3
|
-
description: "Convex reactive database patterns, schema design, real-time queries, mutations, actions, and
|
|
3
|
+
description: "Convex reactive database patterns, schema design, real-time queries, mutations, actions, authentication, migrations, performance optimization, and component creation. Use when designing Convex schemas, writing queries/mutations, managing the Convex backend, setting up auth, migrating data, optimizing performance, or building Convex components."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .opencastle/ directory instead. -->
|
|
@@ -9,6 +9,18 @@ description: "Convex reactive database patterns, schema design, real-time querie
|
|
|
9
9
|
|
|
10
10
|
For project-specific schema, functions, and deployment details, see [database-config.md](../../.opencastle/stack/database-config.md).
|
|
11
11
|
|
|
12
|
+
## Topic Routing
|
|
13
|
+
|
|
14
|
+
Read the matching reference file before writing code for any of these topics:
|
|
15
|
+
|
|
16
|
+
| Topic | Reference |
|
|
17
|
+
|-------|-----------|
|
|
18
|
+
| Project setup & scaffolding | `references/quickstart.md` |
|
|
19
|
+
| Schema & data migrations | `references/migrations.md` |
|
|
20
|
+
| Performance optimization | `references/performance-audit.md` |
|
|
21
|
+
| Authentication & access control | `references/auth-setup.md` |
|
|
22
|
+
| Component creation & isolation | `references/components.md` |
|
|
23
|
+
|
|
12
24
|
## Critical Development Rules
|
|
13
25
|
|
|
14
26
|
**Function Registration**
|
|
@@ -21,9 +33,14 @@ For project-specific schema, functions, and deployment details, see [database-co
|
|
|
21
33
|
|
|
22
34
|
**Queries**
|
|
23
35
|
- Do NOT use `.filter()` — define an index in the schema and use `.withIndex()` instead
|
|
36
|
+
- Convex `.filter()` is equivalent to JS filtering — neither pushes the filter to storage; only `.withIndex()` actually reduces documents scanned
|
|
24
37
|
- Use `.unique()` for single document queries
|
|
25
38
|
- No `.delete()` on queries — collect results, then call `ctx.db.delete(row._id)` on each
|
|
26
39
|
|
|
40
|
+
**Mutations**
|
|
41
|
+
- Schema changes must not break existing documents — use widen-migrate-narrow when adding required fields; see `references/migrations.md`
|
|
42
|
+
- Skip no-op writes: check if values changed before calling `ctx.db.patch()` — no-op writes still trigger invalidation and replication
|
|
43
|
+
|
|
27
44
|
**Actions**
|
|
28
45
|
- Add `"use node";` at the top of files containing actions that use Node.js built-in modules
|
|
29
46
|
- Never use `ctx.db` inside actions — actions don't have database access; use `ctx.runQuery`/`ctx.runMutation` instead
|
|
@@ -32,19 +49,23 @@ For project-specific schema, functions, and deployment details, see [database-co
|
|
|
32
49
|
- Index name must include all fields: `["field1", "field2"]` → `"by_field1_and_field2"`
|
|
33
50
|
- Index fields must be queried in definition order
|
|
34
51
|
- Do NOT define `_id` or `_creationTime` — they are automatic system fields
|
|
52
|
+
- Prefer compound indexes over redundant single-field indexes (e.g. `by_team_and_user` covers both `by_team` queries and `by_team_and_user` queries)
|
|
53
|
+
|
|
54
|
+
**Components**
|
|
55
|
+
- Authentication and environment variables must stay in the app — components cannot access `ctx.auth` or `process.env`
|
|
56
|
+
- Pass parent app IDs across the component boundary as `v.string()`, not `v.id("parentTable")`
|
|
57
|
+
- Import `query`/`mutation`/`action` from the component's own `./_generated/server`, not the app's generated files
|
|
35
58
|
|
|
36
59
|
**General**
|
|
37
60
|
- Schema-first design: define in `convex/schema.ts` using `defineSchema`/`defineTable`
|
|
38
61
|
- Mutations are ACID transactional; use actions for external API calls or side effects
|
|
39
|
-
- Never await queries in mutations — they run in separate contexts
|
|
40
|
-
- Use `.paginate()` for large result sets
|
|
41
|
-
- Use `Id<'tableName'>` for document ID types (from `./_generated/dataModel`)
|
|
42
62
|
- Use `v.null()` not `v.undefined()` — `undefined` is not a valid Convex value
|
|
43
63
|
- Environment variables: set via Convex dashboard; access with `process.env` in actions only
|
|
44
64
|
|
|
45
65
|
## Schema Patterns
|
|
46
66
|
|
|
47
67
|
### Defining Tables
|
|
68
|
+
|
|
48
69
|
```typescript
|
|
49
70
|
import { defineSchema, defineTable } from "convex/server";
|
|
50
71
|
import { v } from "convex/values";
|
|
@@ -61,6 +82,7 @@ export default defineSchema({
|
|
|
61
82
|
```
|
|
62
83
|
|
|
63
84
|
### Query Functions
|
|
85
|
+
|
|
64
86
|
```typescript
|
|
65
87
|
import { query } from "./_generated/server";
|
|
66
88
|
import { v } from "convex/values";
|
|
@@ -80,6 +102,7 @@ export const list = query({
|
|
|
80
102
|
```
|
|
81
103
|
|
|
82
104
|
### Mutations
|
|
105
|
+
|
|
83
106
|
```typescript
|
|
84
107
|
import { mutation } from "./_generated/server";
|
|
85
108
|
import { v } from "convex/values";
|
|
@@ -93,28 +116,47 @@ export const create = mutation({
|
|
|
93
116
|
});
|
|
94
117
|
```
|
|
95
118
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- Use `useQuery` hook for automatic real-time subscriptions
|
|
99
|
-
- Queries re-run when any referenced table data changes
|
|
100
|
-
- Use `useMutation` for optimistic updates
|
|
101
|
-
- Paginated queries support real-time updates with `.paginate()`
|
|
119
|
+
### Protecting Functions with Auth
|
|
102
120
|
|
|
103
|
-
|
|
121
|
+
```typescript
|
|
122
|
+
import { query } from "./_generated/server";
|
|
104
123
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
export const getMyProfile = query({
|
|
125
|
+
args: {},
|
|
126
|
+
handler: async (ctx) => {
|
|
127
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
128
|
+
if (!identity) throw new Error("Not authenticated");
|
|
129
|
+
|
|
130
|
+
return await ctx.db
|
|
131
|
+
.query("users")
|
|
132
|
+
.withIndex("by_tokenIdentifier", (q) =>
|
|
133
|
+
q.eq("tokenIdentifier", identity.tokenIdentifier)
|
|
134
|
+
)
|
|
135
|
+
.unique();
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
```
|
|
109
139
|
|
|
110
140
|
## Quick Workflow: Implement a schema change and deploy
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
|
|
142
|
+
1. Read `references/migrations.md` if the change is breaking (adding required fields, changing types, deleting fields)
|
|
143
|
+
2. Add or modify schema in `convex/schema.ts` and run `npx convex dev` locally; confirm the dev server starts and responds. Run a small validation script or sample queries to verify schema changes.
|
|
144
|
+
3. Write queries/mutations with `returns` validators and unit test against the dev server.
|
|
145
|
+
4. Run `npx convex deploy` to push the change to production.
|
|
146
|
+
5. Verify real-time queries in the app and run a quick smoke check:
|
|
115
147
|
|
|
116
148
|
```bash
|
|
117
149
|
curl -fsS https://<APP_URL>/health || (echo "health check failed" && exit 1)
|
|
118
150
|
```
|
|
119
151
|
|
|
120
|
-
If an issue occurs: roll back via `npx convex import` of the last good export, fix locally, and re-deploy.
|
|
152
|
+
If an issue occurs: roll back via `npx convex import` of the last good export, fix locally, and re-deploy.
|
|
153
|
+
|
|
154
|
+
## Validation Checkpoints
|
|
155
|
+
|
|
156
|
+
| Step | Checkpoint |
|
|
157
|
+
|------|-----------|
|
|
158
|
+
| Schema change | `npx convex dev` starts without errors |
|
|
159
|
+
| Migration needed | `references/migrations.md` checklist completed |
|
|
160
|
+
| Auth function | `ctx.auth.getUserIdentity()` returns non-null in test |
|
|
161
|
+
| Deploy | Smoke check passes; no `convex insights` regressions |
|
|
162
|
+
| Component | `npx convex codegen` succeeds; sibling functions inspected |
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Auth0
|
|
2
|
+
|
|
3
|
+
Official docs:
|
|
4
|
+
|
|
5
|
+
- https://docs.convex.dev/auth/auth0
|
|
6
|
+
- https://auth0.github.io/auth0-cli/
|
|
7
|
+
- https://auth0.github.io/auth0-cli/auth0_apps_create.html
|
|
8
|
+
|
|
9
|
+
Use this when the app already uses Auth0 or the user wants Auth0 specifically.
|
|
10
|
+
|
|
11
|
+
## Workflow
|
|
12
|
+
|
|
13
|
+
1. Confirm the user wants Auth0
|
|
14
|
+
2. Determine the app framework and whether Auth0 is already partly set up
|
|
15
|
+
3. Ask whether the user wants local-only setup or production-ready setup now
|
|
16
|
+
4. Read the official Convex and Auth0 guides before making changes
|
|
17
|
+
5. Ask whether they want the fastest setup path by installing the Auth0 CLI
|
|
18
|
+
6. If they agree, install the Auth0 CLI and do as much of the Auth0 app setup as possible through the CLI
|
|
19
|
+
7. If they do not want the CLI path, use the Auth0 dashboard path instead
|
|
20
|
+
8. Complete the relevant Auth0 frontend quickstart if the app does not already have Auth0 wired up
|
|
21
|
+
9. Configure `convex/auth.config.ts` with the Auth0 domain and client ID
|
|
22
|
+
10. Set environment variables for local and production environments
|
|
23
|
+
11. Wrap the app with `Auth0Provider` and `ConvexProviderWithAuth0`
|
|
24
|
+
12. Gate Convex-backed UI with Convex auth state
|
|
25
|
+
13. Try to verify Convex reports the user as authenticated after Auth0 login
|
|
26
|
+
14. If the refresh-token path fails, stop improvising and send the user back to the official docs
|
|
27
|
+
15. If the user wants production-ready setup, make sure the production Auth0 tenant and env vars are also covered
|
|
28
|
+
|
|
29
|
+
## What To Do
|
|
30
|
+
|
|
31
|
+
- Read the official Convex and Auth0 guide before writing setup code
|
|
32
|
+
- Prefer the Auth0 CLI path for mechanical setup if the user is willing to install it, but do not present it as a fully validated end-to-end path yet
|
|
33
|
+
- Ask the user directly: "The fastest path is to install the Auth0 CLI so I can do more of this for you. If you want, I can install it and then only ask you to log in when needed. Would you like me to do that?"
|
|
34
|
+
- Make sure the app has already completed the relevant Auth0 quickstart for its frontend
|
|
35
|
+
- Use the official examples for `Auth0Provider` and `ConvexProviderWithAuth0`
|
|
36
|
+
- If the Auth0 login or refresh flow starts failing in a way that is not clearly explained by the docs, say that plainly and fall back to the official docs instead of pretending the flow is validated
|
|
37
|
+
|
|
38
|
+
## Key Setup Areas
|
|
39
|
+
|
|
40
|
+
- install the Auth0 SDK for the app's framework
|
|
41
|
+
- configure `convex/auth.config.ts` with the Auth0 domain and client ID
|
|
42
|
+
- set environment variables for local and production environments
|
|
43
|
+
- wrap the app with `Auth0Provider` and `ConvexProviderWithAuth0`
|
|
44
|
+
- use Convex auth state when gating Convex-backed UI
|
|
45
|
+
|
|
46
|
+
## Files and Env Vars To Expect
|
|
47
|
+
|
|
48
|
+
- `convex/auth.config.ts`
|
|
49
|
+
- frontend app entry or provider wrapper
|
|
50
|
+
- Auth0 CLI install docs: `https://auth0.github.io/auth0-cli/`
|
|
51
|
+
- Auth0 environment variables commonly include:
|
|
52
|
+
- `AUTH0_DOMAIN`
|
|
53
|
+
- `AUTH0_CLIENT_ID`
|
|
54
|
+
- `VITE_AUTH0_DOMAIN`
|
|
55
|
+
- `VITE_AUTH0_CLIENT_ID`
|
|
56
|
+
|
|
57
|
+
## Concrete Steps
|
|
58
|
+
|
|
59
|
+
1. Start by reading `https://docs.convex.dev/auth/auth0` and the relevant Auth0 quickstart for the app's framework
|
|
60
|
+
2. Ask whether the user wants the Auth0 CLI path
|
|
61
|
+
3. If yes, install Auth0 CLI and have the user authenticate it with `auth0 login`
|
|
62
|
+
4. Use `auth0 apps create` with SPA settings, callback URL, logout URL, and web origins if creating a new app
|
|
63
|
+
5. If not using the CLI path, complete the relevant Auth0 frontend quickstart and create the Auth0 app in the dashboard
|
|
64
|
+
6. Get the Auth0 domain and client ID from the CLI output or the Auth0 dashboard
|
|
65
|
+
7. Install the Auth0 SDK for the app's framework
|
|
66
|
+
8. Create or update `convex/auth.config.ts` with the Auth0 domain and client ID
|
|
67
|
+
9. Set frontend and backend environment variables
|
|
68
|
+
10. Wrap the app in `Auth0Provider`
|
|
69
|
+
11. Replace plain `ConvexProvider` wiring with `ConvexProviderWithAuth0`
|
|
70
|
+
12. Run the normal Convex dev or deploy flow after backend config changes
|
|
71
|
+
13. Try the official provider config shown in the Convex docs
|
|
72
|
+
14. If login works but Convex auth or token refresh fails in a way you cannot clearly resolve, stop and tell the user to follow the official docs manually for now
|
|
73
|
+
15. Only claim success if the user can sign in and Convex recognizes the authenticated session
|
|
74
|
+
16. If the user wants production-ready setup, configure the production Auth0 tenant values and production environment variables too
|
|
75
|
+
|
|
76
|
+
## Gotchas
|
|
77
|
+
|
|
78
|
+
- The Convex docs assume the Auth0 side is already set up, so do not skip the Auth0 quickstart if the app is starting from scratch
|
|
79
|
+
- The Auth0 CLI is often the fastest path for a fresh setup, but it still requires the user to authenticate the CLI to their Auth0 tenant
|
|
80
|
+
- If the user agrees to install the Auth0 CLI, do the mechanical setup yourself instead of bouncing them through the dashboard
|
|
81
|
+
- If login succeeds but Convex still reports unauthenticated, double-check `convex/auth.config.ts` and whether the backend config was synced
|
|
82
|
+
- We were able to automate Auth0 app creation and Convex config wiring, but we did not fully validate the refresh-token path end to end
|
|
83
|
+
- In validation, the documented `useRefreshTokens={true}` and `cacheLocation="localstorage"` setup hit refresh-token failures, so do not present that path as settled
|
|
84
|
+
- If you hit Auth0 errors like `Unknown or invalid refresh token`, do not keep inventing fixes indefinitely, send the user back to the official docs and explain that this path is still under investigation
|
|
85
|
+
- Keep dev and prod tenants separate if the project uses different Auth0 environments
|
|
86
|
+
- Do not confuse "Auth0 login works" with "Convex can validate the Auth0 token". Both need to work.
|
|
87
|
+
- If the repo already uses Auth0, preserve existing redirect and tenant configuration unless the user asked to change it.
|
|
88
|
+
- Do not assume the local Auth0 tenant settings match production. Verify the production domain, client ID, and callback URLs separately.
|
|
89
|
+
- For local dev, make sure the Auth0 app settings match the app's real local port for callback URLs, logout URLs, and web origins
|
|
90
|
+
|
|
91
|
+
## Production
|
|
92
|
+
|
|
93
|
+
- Ask whether the user wants dev-only setup or production-ready setup
|
|
94
|
+
- If the answer is production-ready, make sure the production Auth0 tenant values, callback URLs, and Convex deployment config are all covered
|
|
95
|
+
- Verify production environment variables and redirect settings before calling the task complete
|
|
96
|
+
- Do not silently write a notes file into the repo by default. If the user wants rollout or handoff docs, create one explicitly.
|
|
97
|
+
|
|
98
|
+
## Validation
|
|
99
|
+
|
|
100
|
+
- Verify the user can complete the Auth0 login flow
|
|
101
|
+
- Verify Convex-authenticated UI renders only after Convex auth state is ready
|
|
102
|
+
- Verify protected Convex queries succeed after login
|
|
103
|
+
- Verify `ctx.auth.getUserIdentity()` is non-null in protected backend functions
|
|
104
|
+
- Verify the Auth0 app settings match the real local callback and logout URLs during development
|
|
105
|
+
- If the Auth0 refresh-token path fails, mark the setup as not fully validated and direct the user to the official docs instead of claiming the skill completed successfully
|
|
106
|
+
- If production-ready setup was requested, verify the production Auth0 configuration is also covered
|
|
107
|
+
|
|
108
|
+
## Checklist
|
|
109
|
+
|
|
110
|
+
- [ ] Confirm the user wants Auth0
|
|
111
|
+
- [ ] Ask whether the user wants local-only setup or production-ready setup
|
|
112
|
+
- [ ] Complete the relevant Auth0 frontend setup
|
|
113
|
+
- [ ] Configure `convex/auth.config.ts`
|
|
114
|
+
- [ ] Set environment variables
|
|
115
|
+
- [ ] Verify Convex authenticated state after login, or explicitly tell the user this path is still under investigation and send them to the official docs
|
|
116
|
+
- [ ] If requested, configure the production deployment too
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Clerk
|
|
2
|
+
|
|
3
|
+
Official docs:
|
|
4
|
+
|
|
5
|
+
- https://docs.convex.dev/auth/clerk
|
|
6
|
+
- https://clerk.com/docs/guides/development/integrations/databases/convex
|
|
7
|
+
|
|
8
|
+
Use this when the app already uses Clerk or the user wants Clerk's hosted auth features.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Confirm the user wants Clerk
|
|
13
|
+
2. Make sure the user has a Clerk account and a Clerk application
|
|
14
|
+
3. Determine the app framework:
|
|
15
|
+
- React
|
|
16
|
+
- Next.js
|
|
17
|
+
- TanStack Start
|
|
18
|
+
4. Ask whether the user wants local-only setup or production-ready setup now
|
|
19
|
+
5. Gather the Clerk keys and the Clerk Frontend API URL
|
|
20
|
+
6. Follow the correct framework section in the official docs
|
|
21
|
+
7. Complete the backend and client wiring
|
|
22
|
+
8. Verify Convex reports the user as authenticated after login
|
|
23
|
+
9. If the user wants production-ready setup, make sure the production Clerk config is also covered
|
|
24
|
+
|
|
25
|
+
## What To Do
|
|
26
|
+
|
|
27
|
+
- Read the official Convex and Clerk guide before writing setup code
|
|
28
|
+
- If the user does not already have Clerk set up, send them to `https://dashboard.clerk.com/sign-up` to create an account and `https://dashboard.clerk.com/apps/new` to create an application
|
|
29
|
+
- Send the user to `https://dashboard.clerk.com/apps/setup/convex` if the Convex integration is not already active
|
|
30
|
+
- Match the guide to the app's framework, usually React, Next.js, or TanStack Start
|
|
31
|
+
- Use the official examples for `ConvexProviderWithClerk`, `ClerkProvider`, and `useAuth`
|
|
32
|
+
|
|
33
|
+
## Key Setup Areas
|
|
34
|
+
|
|
35
|
+
- install the Clerk SDK for the framework in use
|
|
36
|
+
- configure `convex/auth.config.ts` with the Clerk issuer domain
|
|
37
|
+
- set the required Clerk environment variables
|
|
38
|
+
- wrap the app with `ClerkProvider` and `ConvexProviderWithClerk`
|
|
39
|
+
- use Convex auth-aware UI patterns such as `Authenticated`, `Unauthenticated`, and `AuthLoading`
|
|
40
|
+
|
|
41
|
+
## Files and Env Vars To Expect
|
|
42
|
+
|
|
43
|
+
- `convex/auth.config.ts`
|
|
44
|
+
- React or Vite client entry such as `src/main.tsx`
|
|
45
|
+
- Next.js client wrapper for Convex if using App Router
|
|
46
|
+
- Clerk account sign-up page: `https://dashboard.clerk.com/sign-up`
|
|
47
|
+
- Clerk app creation page: `https://dashboard.clerk.com/apps/new`
|
|
48
|
+
- Clerk Convex integration page: `https://dashboard.clerk.com/apps/setup/convex`
|
|
49
|
+
- Clerk API keys page: `https://dashboard.clerk.com/last-active?path=api-keys`
|
|
50
|
+
- Clerk environment variables:
|
|
51
|
+
- `CLERK_JWT_ISSUER_DOMAIN` for Convex backend validation in the Convex docs
|
|
52
|
+
- `CLERK_FRONTEND_API_URL` in the Clerk docs
|
|
53
|
+
- `VITE_CLERK_PUBLISHABLE_KEY` for Vite apps
|
|
54
|
+
- `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` for Next.js apps
|
|
55
|
+
- `CLERK_SECRET_KEY` for Next.js server-side Clerk setup where required
|
|
56
|
+
|
|
57
|
+
`CLERK_JWT_ISSUER_DOMAIN` and `CLERK_FRONTEND_API_URL` refer to the same Clerk Frontend API URL value. Do not treat them as two different URLs.
|
|
58
|
+
|
|
59
|
+
## Concrete Steps
|
|
60
|
+
|
|
61
|
+
1. If needed, create a Clerk account at `https://dashboard.clerk.com/sign-up`
|
|
62
|
+
2. If needed, create a Clerk application at `https://dashboard.clerk.com/apps/new`
|
|
63
|
+
3. Open `https://dashboard.clerk.com/last-active?path=api-keys` and copy the publishable key, plus the secret key for Next.js where needed
|
|
64
|
+
4. Open `https://dashboard.clerk.com/apps/setup/convex`
|
|
65
|
+
5. Activate the Convex integration in Clerk if it is not already active
|
|
66
|
+
6. Copy the Clerk Frontend API URL shown there
|
|
67
|
+
7. Install the Clerk package for the app's framework
|
|
68
|
+
8. Create or update `convex/auth.config.ts` so Convex validates Clerk tokens
|
|
69
|
+
9. Set the publishable key in the frontend environment
|
|
70
|
+
10. Set the issuer domain or Frontend API URL so Convex can validate the JWT
|
|
71
|
+
11. Replace plain `ConvexProvider` wiring with `ConvexProviderWithClerk`
|
|
72
|
+
12. Wrap the app in `ClerkProvider`
|
|
73
|
+
13. Use Convex auth helpers for authenticated rendering
|
|
74
|
+
14. Run the normal Convex dev or deploy flow after updating backend auth config
|
|
75
|
+
15. If the user wants production-ready setup, configure the production Clerk values and production issuer domain too
|
|
76
|
+
|
|
77
|
+
## Gotchas
|
|
78
|
+
|
|
79
|
+
- Prefer `useConvexAuth()` over raw Clerk auth state when deciding whether Convex-authenticated UI can render
|
|
80
|
+
- For Next.js, keep server and client boundaries in mind when creating the Convex provider wrapper
|
|
81
|
+
- After changing `convex/auth.config.ts`, run the normal Convex dev or deploy flow so the backend picks up the new config
|
|
82
|
+
- Do not stop at "Clerk login works". The important check is that Convex also sees the session and can authenticate requests.
|
|
83
|
+
- If the repo already uses Clerk, preserve its existing auth flow unless the user asked to change it.
|
|
84
|
+
- Do not assume the same Clerk values work for both dev and production. Check the production issuer domain and publishable key separately.
|
|
85
|
+
- The Convex setup page is where you get the Clerk Frontend API URL for Convex. Keep using the Clerk API keys page for the publishable key and the secret key.
|
|
86
|
+
- If Convex says no auth provider matched the token, first confirm the Clerk Convex integration was activated at `https://dashboard.clerk.com/apps/setup/convex`
|
|
87
|
+
- After activating the Clerk Convex integration, sign out completely and sign back in before retesting. An old Clerk session can keep using a token that Convex rejects.
|
|
88
|
+
|
|
89
|
+
## Production
|
|
90
|
+
|
|
91
|
+
- Ask whether the user wants dev-only setup or production-ready setup
|
|
92
|
+
- If the answer is production-ready, make sure production Clerk keys and issuer configuration are included
|
|
93
|
+
- Verify production redirect URLs and any production Clerk domain values before calling the task complete
|
|
94
|
+
- Do not silently write a notes file into the repo by default. If the user wants rollout or handoff docs, create one explicitly.
|
|
95
|
+
|
|
96
|
+
## Validation
|
|
97
|
+
|
|
98
|
+
- Verify the user can sign in with Clerk
|
|
99
|
+
- If the Clerk integration was just activated, verify after a full Clerk sign-out and fresh sign-in
|
|
100
|
+
- Verify `useConvexAuth()` reaches the authenticated state after Clerk login
|
|
101
|
+
- Verify protected Convex queries run successfully inside authenticated UI
|
|
102
|
+
- Verify `ctx.auth.getUserIdentity()` is non-null in protected backend functions
|
|
103
|
+
- If production-ready setup was requested, verify the production Clerk configuration is also covered
|
|
104
|
+
|
|
105
|
+
## Checklist
|
|
106
|
+
|
|
107
|
+
- [ ] Confirm the user wants Clerk
|
|
108
|
+
- [ ] Ask whether the user wants local-only setup or production-ready setup
|
|
109
|
+
- [ ] Follow the correct framework section in the official guide
|
|
110
|
+
- [ ] Set Clerk environment variables
|
|
111
|
+
- [ ] Configure `convex/auth.config.ts`
|
|
112
|
+
- [ ] Verify Convex authenticated state after login
|
|
113
|
+
- [ ] If requested, configure the production deployment too
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Convex Auth
|
|
2
|
+
|
|
3
|
+
Official docs: https://docs.convex.dev/auth/convex-auth
|
|
4
|
+
Setup guide: https://labs.convex.dev/auth/setup
|
|
5
|
+
|
|
6
|
+
Use this when the user wants auth handled directly in Convex rather than through a third-party provider.
|
|
7
|
+
|
|
8
|
+
## Workflow
|
|
9
|
+
|
|
10
|
+
1. Confirm the user wants Convex Auth specifically
|
|
11
|
+
2. Determine which sign-in methods the app needs:
|
|
12
|
+
- magic links or OTPs
|
|
13
|
+
- OAuth providers
|
|
14
|
+
- passwords and password reset
|
|
15
|
+
3. Ask whether the user wants local-only setup or production-ready setup now
|
|
16
|
+
4. Read the Convex Auth setup guide before writing code
|
|
17
|
+
5. Make sure the project has a configured Convex deployment:
|
|
18
|
+
- run `npx convex dev` first if `CONVEX_DEPLOYMENT` is not set
|
|
19
|
+
- if CLI configuration requires interactive human input, stop and ask the user to complete that step before continuing
|
|
20
|
+
6. Install the auth packages:
|
|
21
|
+
- `npm install @convex-dev/auth @auth/core@0.37.0`
|
|
22
|
+
7. Run the initialization command:
|
|
23
|
+
- `npx @convex-dev/auth`
|
|
24
|
+
8. Confirm the initializer created:
|
|
25
|
+
- `convex/auth.config.ts`
|
|
26
|
+
- `convex/auth.ts`
|
|
27
|
+
- `convex/http.ts`
|
|
28
|
+
9. Add the required `authTables` to `convex/schema.ts`
|
|
29
|
+
10. Replace plain `ConvexProvider` wiring with `ConvexAuthProvider`
|
|
30
|
+
11. Configure at least one auth method in `convex/auth.ts`
|
|
31
|
+
12. Run `npx convex dev --once` or the normal dev flow to push the updated schema and generated code
|
|
32
|
+
13. Verify the client can sign in successfully
|
|
33
|
+
14. Verify Convex receives authenticated identity in backend functions
|
|
34
|
+
15. If the user wants production-ready setup, make sure the same auth setup is configured for the production deployment as well
|
|
35
|
+
16. Only add a `users` table and `storeUser` flow if the app needs app-level user records inside Convex
|
|
36
|
+
|
|
37
|
+
## What This Reference Is For
|
|
38
|
+
|
|
39
|
+
- choosing Convex Auth as the default provider for a new Convex app
|
|
40
|
+
- understanding whether the app wants magic links, OTPs, OAuth, or passwords
|
|
41
|
+
- keeping the setup provider-specific while using the official Convex Auth docs for identity and authorization behavior
|
|
42
|
+
|
|
43
|
+
## What To Do
|
|
44
|
+
|
|
45
|
+
- Read the Convex Auth setup guide before writing setup code
|
|
46
|
+
- Follow the setup flow from the docs rather than recreating it from memory
|
|
47
|
+
- If the app is new, consider starting from the official starter flow instead of hand-wiring everything
|
|
48
|
+
- Treat `npx @convex-dev/auth` as a required initialization step for existing apps, not an optional extra
|
|
49
|
+
|
|
50
|
+
## Concrete Steps
|
|
51
|
+
|
|
52
|
+
1. Install `@convex-dev/auth` and `@auth/core@0.37.0`
|
|
53
|
+
2. Run `npx convex dev` if the project does not already have a configured deployment
|
|
54
|
+
3. If `npx convex dev` blocks on interactive setup, ask the user explicitly to finish configuring the Convex deployment
|
|
55
|
+
4. Run `npx @convex-dev/auth`
|
|
56
|
+
5. Confirm the generated auth setup is present before continuing:
|
|
57
|
+
- `convex/auth.config.ts`
|
|
58
|
+
- `convex/auth.ts`
|
|
59
|
+
- `convex/http.ts`
|
|
60
|
+
6. Add `authTables` to `convex/schema.ts`
|
|
61
|
+
7. Replace `ConvexProvider` with `ConvexAuthProvider` in the app entry
|
|
62
|
+
8. Configure the selected auth methods in `convex/auth.ts`
|
|
63
|
+
9. Run `npx convex dev --once` or the normal dev flow so the updated schema and auth files are pushed
|
|
64
|
+
10. Verify login locally
|
|
65
|
+
11. If the user wants production-ready setup, repeat the required auth configuration against the production deployment
|
|
66
|
+
|
|
67
|
+
## Expected Files and Decisions
|
|
68
|
+
|
|
69
|
+
- `convex/schema.ts`
|
|
70
|
+
- frontend app entry such as `src/main.tsx` or the framework-equivalent provider file
|
|
71
|
+
- generated Convex Auth setup produced by `npx @convex-dev/auth`
|
|
72
|
+
- an existing configured Convex deployment, or the ability to create one with `npx convex dev`
|
|
73
|
+
- `convex/auth.ts` starts with `providers: []` until the app configures actual sign-in methods
|
|
74
|
+
|
|
75
|
+
- Decide whether the user is creating a new app or adding auth to an existing app
|
|
76
|
+
- For a new app, prefer the official starter flow instead of rebuilding setup by hand
|
|
77
|
+
- Decide which auth methods the app needs:
|
|
78
|
+
- magic links or OTPs
|
|
79
|
+
- OAuth providers
|
|
80
|
+
- passwords
|
|
81
|
+
- Decide whether the user wants local-only setup or production-ready setup now
|
|
82
|
+
- Decide whether the app actually needs a `users` table inside Convex, or whether provider identity alone is enough
|
|
83
|
+
|
|
84
|
+
## Gotchas
|
|
85
|
+
|
|
86
|
+
- Do not assume a specific sign-in method. Ask which methods the app needs before wiring UI and backend behavior.
|
|
87
|
+
- `npx @convex-dev/auth` is important because it initializes the auth setup, including the key material. Do not skip it when adding Convex Auth to an existing project.
|
|
88
|
+
- `npx @convex-dev/auth` will fail if the project does not already have a configured `CONVEX_DEPLOYMENT`.
|
|
89
|
+
- `npx convex dev` may require interactive setup for deployment creation or project selection. If that happens, ask the user explicitly for that human step instead of guessing.
|
|
90
|
+
- `npx @convex-dev/auth` does not finish the whole integration by itself. You still need to add `authTables`, swap in `ConvexAuthProvider`, and configure at least one auth method.
|
|
91
|
+
- A project can still build even if `convex/auth.ts` still has `providers: []`, so do not treat a successful build as proof that sign-in is fully configured.
|
|
92
|
+
- Convex Auth does not mean every app needs a `users` table. If the app only needs authentication gates, `ctx.auth.getUserIdentity()` may be enough.
|
|
93
|
+
- If the app is greenfield, starting from the official starter flow is usually better than partially recreating it by hand.
|
|
94
|
+
- Do not stop at local dev setup if the user expects production-ready auth. The production deployment needs the auth setup too.
|
|
95
|
+
- Keep provider-specific setup and Convex Auth authorization behavior in the official docs instead of inventing shared patterns from memory.
|
|
96
|
+
|
|
97
|
+
## Production
|
|
98
|
+
|
|
99
|
+
- Ask whether the user wants dev-only setup or production-ready setup
|
|
100
|
+
- If the answer is production-ready, make sure the auth configuration is applied to the production deployment, not just the dev deployment
|
|
101
|
+
- Verify production-specific redirect URLs, auth method configuration, and deployment settings before calling the task complete
|
|
102
|
+
- Do not silently write a notes file into the repo by default. If the user wants rollout or handoff docs, create one explicitly.
|
|
103
|
+
|
|
104
|
+
## Human Handoff
|
|
105
|
+
|
|
106
|
+
If `npx convex dev` or deployment setup requires human input:
|
|
107
|
+
|
|
108
|
+
- stop and explain exactly what the user needs to do
|
|
109
|
+
- say why that step is required
|
|
110
|
+
- resume the auth setup immediately after the user confirms it is done
|
|
111
|
+
|
|
112
|
+
## Validation
|
|
113
|
+
|
|
114
|
+
- Verify the user can complete a sign-in flow
|
|
115
|
+
- Offer to validate sign up, sign out, and sign back in with the configured auth method
|
|
116
|
+
- If browser automation is available in the environment, you can do this directly
|
|
117
|
+
- If browser automation is not available, give the user a short manual validation checklist instead
|
|
118
|
+
- Verify `ctx.auth.getUserIdentity()` returns an identity in protected backend functions
|
|
119
|
+
- Verify protected UI only renders after Convex-authenticated state is ready
|
|
120
|
+
- Verify environment variables and redirect settings match the current app environment
|
|
121
|
+
- Verify `convex/auth.ts` no longer has an empty `providers: []` configuration once the app is meant to support real sign-in
|
|
122
|
+
- Run `npx convex dev --once` or the normal dev flow after setup changes and confirm Convex codegen and push succeed
|
|
123
|
+
- If production-ready setup was requested, verify the production deployment is also configured correctly
|
|
124
|
+
|
|
125
|
+
## Checklist
|
|
126
|
+
|
|
127
|
+
- [ ] Confirm the user wants Convex Auth specifically
|
|
128
|
+
- [ ] Ask whether the user wants local-only setup or production-ready setup
|
|
129
|
+
- [ ] Ensure a Convex deployment is configured before running auth initialization
|
|
130
|
+
- [ ] Install `@convex-dev/auth` and `@auth/core@0.37.0`
|
|
131
|
+
- [ ] Run `npx convex dev` first if needed
|
|
132
|
+
- [ ] Run `npx @convex-dev/auth`
|
|
133
|
+
- [ ] Confirm `convex/auth.config.ts`, `convex/auth.ts`, and `convex/http.ts` were created
|
|
134
|
+
- [ ] Follow the setup guide for package install and wiring
|
|
135
|
+
- [ ] Add `authTables` to `convex/schema.ts`
|
|
136
|
+
- [ ] Replace `ConvexProvider` with `ConvexAuthProvider`
|
|
137
|
+
- [ ] Configure at least one auth method in `convex/auth.ts`
|
|
138
|
+
- [ ] Run `npx convex dev --once` or the normal dev flow after setup changes
|
|
139
|
+
- [ ] Confirm which sign-in methods the app needs
|
|
140
|
+
- [ ] Verify the client can sign in and the backend receives authenticated identity
|
|
141
|
+
- [ ] Offer end-to-end validation of sign up, sign out, and sign back in
|
|
142
|
+
- [ ] If requested, configure the production deployment too
|
|
143
|
+
- [ ] Only add extra `users` table sync if the app needs app-level user records
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Convex Authentication Setup
|
|
2
|
+
|
|
3
|
+
Implement secure authentication in Convex with user management and access control.
|
|
4
|
+
|
|
5
|
+
## Step 1: Choose the Auth Provider
|
|
6
|
+
|
|
7
|
+
Do not assume a provider. Before writing setup code:
|
|
8
|
+
1. Ask the user which auth solution they want, unless the repository already makes it obvious
|
|
9
|
+
2. If the repo already uses a provider, continue with that provider unless the user wants to switch
|
|
10
|
+
|
|
11
|
+
Check for signals: dependencies like `@clerk/*`, `@workos-inc/*`, `@auth0/*`, or Convex Auth packages; files like `convex/auth.config.ts`; environment variables pointing at a provider.
|
|
12
|
+
|
|
13
|
+
| Provider | Use when |
|
|
14
|
+
|----------|----------|
|
|
15
|
+
| Convex Auth | Good default when the user wants auth handled directly in Convex |
|
|
16
|
+
| Clerk | App already uses Clerk or user wants Clerk's hosted auth features |
|
|
17
|
+
| WorkOS AuthKit | App already uses WorkOS or user wants AuthKit specifically |
|
|
18
|
+
| Auth0 | App already uses Auth0 |
|
|
19
|
+
| Custom JWT | Integrating an existing auth system not covered above |
|
|
20
|
+
|
|
21
|
+
## Provider References
|
|
22
|
+
|
|
23
|
+
- Convex Auth: [official docs](https://docs.convex.dev/auth/convex-auth) + `references/auth-convex-auth.md`
|
|
24
|
+
- Clerk: [official docs](https://docs.convex.dev/auth/clerk) + `references/auth-clerk.md`
|
|
25
|
+
- WorkOS AuthKit: [official docs](https://docs.convex.dev/auth/authkit/) + `references/auth-workos.md`
|
|
26
|
+
- Auth0: [official docs](https://docs.convex.dev/auth/auth0) + `references/auth-auth0.md`
|
|
27
|
+
|
|
28
|
+
## Core Pattern: Protecting Backend Functions
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// Bad: trusting a client-provided userId
|
|
32
|
+
export const getMyProfile = query({
|
|
33
|
+
args: { userId: v.id("users") },
|
|
34
|
+
handler: async (ctx, args) => {
|
|
35
|
+
return await ctx.db.get(args.userId);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// Good: verifying identity server-side
|
|
42
|
+
export const getMyProfile = query({
|
|
43
|
+
args: {},
|
|
44
|
+
handler: async (ctx) => {
|
|
45
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
46
|
+
if (!identity) throw new Error("Not authenticated");
|
|
47
|
+
|
|
48
|
+
return await ctx.db
|
|
49
|
+
.query("users")
|
|
50
|
+
.withIndex("by_tokenIdentifier", (q) =>
|
|
51
|
+
q.eq("tokenIdentifier", identity.tokenIdentifier)
|
|
52
|
+
)
|
|
53
|
+
.unique();
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Workflow
|
|
59
|
+
|
|
60
|
+
1. Determine the provider (ask or infer from repo)
|
|
61
|
+
2. Read the matching provider reference file
|
|
62
|
+
3. Follow the official provider docs for current setup details
|
|
63
|
+
4. Follow the official Convex docs for shared backend auth behavior:
|
|
64
|
+
- [Auth in Functions](https://docs.convex.dev/auth/functions-auth) — `ctx.auth.getUserIdentity()`
|
|
65
|
+
- [Storing Users](https://docs.convex.dev/auth/database-auth) — optional app-level user storage
|
|
66
|
+
5. Only add a `users` table and `storeUser` flow if the app actually needs user documents in Convex
|
|
67
|
+
6. Add authorization checks for ownership, roles, or team access only where the app needs them
|
|
68
|
+
7. Verify login state, protected queries, environment variables, and production configuration
|
|
69
|
+
|
|
70
|
+
## Key Rules
|
|
71
|
+
|
|
72
|
+
- For Convex Auth, follow built-in auth tables — don't add a parallel `users` table + `storeUser` flow
|
|
73
|
+
- For third-party providers, only add app-level user storage if the app needs user documents in Convex
|
|
74
|
+
- After running provider initialization commands, verify generated files and complete post-init wiring
|
|
75
|
+
- Prefer `useConvexAuth()` over raw provider auth state when deciding whether Convex-authenticated UI can render
|
|
76
|
+
|
|
77
|
+
## Checklist
|
|
78
|
+
|
|
79
|
+
- [ ] Chosen auth provider
|
|
80
|
+
- [ ] Read the matching provider reference file
|
|
81
|
+
- [ ] Used official provider docs for provider-specific wiring
|
|
82
|
+
- [ ] Used official Convex docs for shared auth behavior
|
|
83
|
+
- [ ] Only added app-level user storage if the app needs it
|
|
84
|
+
- [ ] Added `ctx.auth.getUserIdentity()` checks in protected backend functions
|
|
85
|
+
- [ ] Clear error messages ("Not authenticated", "Unauthorized")
|
|
86
|
+
- [ ] Client auth provider configured
|
|
87
|
+
- [ ] Production auth setup covered if requested
|