You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set `STACK_PROJECT_ID` in your Convex dashboard environment variables. Convex runs outside your Next.js process, so it reads the variables configured for the Convex deployment.
51
+
52
+
Next, update or create a file in `convex/convex.config.ts`:
It does not include `teamId`, `selectedTeam`, or a teams list.
145
+
146
+
For mutations, read the user from `ctx` instead of accepting a user ID from the client:
147
+
148
+
```ts
149
+
import { v } from"convex/values";
150
+
import { mutation } from"./_generated/server";
151
+
import { stackServerApp } from"../stack/server";
152
+
153
+
exportconst createNote =mutation({
154
+
args: {
155
+
text: v.string(),
156
+
},
157
+
handler: async (ctx, args) => {
158
+
const user =awaitstackServerApp.getPartialUser({ from: "convex", ctx });
159
+
160
+
if (user===null) {
161
+
thrownewError("User must be signed in to create a note.");
162
+
}
163
+
164
+
returnawaitctx.db.insert("notes", {
165
+
text: args.text,
166
+
ownerUserId: user.id,
167
+
});
168
+
},
169
+
});
170
+
```
171
+
172
+
### Full users and teams
173
+
174
+
If you need Stack Auth team data, use the full Stack user from a Next.js route handler or a Convex action. Full users have APIs such as `user.selectedTeam` and `await user.listTeams()`.
175
+
176
+
In a Next.js route handler:
177
+
178
+
```ts
179
+
const user =awaitstackServerApp.getUser({ tokenStore: request });
180
+
const teams =user===null? [] :awaituser.listTeams();
returnNextResponse.json({ error: "text must be a string" }, { status: 400 });
260
+
}
261
+
262
+
const noteId =awaitfetchMutation(api.myFunctions.createNote, { text }, { token });
263
+
264
+
returnNextResponse.json({ noteId });
265
+
}
266
+
```
267
+
268
+
In `fetchQuery(api.myFunctions.getUserInfo, {}, { token })`, the second argument is the query args object, and the third argument is where the auth token goes.
269
+
80
270
You can find the production-ready template with Stack-Auth, Convex & Shadcn pre-configured [here on GitHub](https://github.com/developing-gamer/next-convex-stack-template).
0 commit comments