#Running a mutation after sign-in
11 messages · Page 1 of 1 (latest)
I tried, in my React login form event handler putting:
const result = await signIn("password", formData);
if (result.signingIn) {
await createProfileAndEnrollment({
cohortId: cohortId as Id<"cohorts">,
});
The mutation fails when it tries to get the auth ID:
export const createProfileAndEnrollment = mutation({
args: {
cohortId: v.id("cohorts"),
name: v.optional(v.string()),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) {
throw new Error("Authentication required");
}
You could do it here: https://labs.convex.dev/auth/advanced#writing-additional-data-during-authentication
Thanks. I need to enroll them in a specific cohort though. How do I pass in the cohortId to this callback?
Wow, this is overly complicated. I hope there's improvements coming for this flow.
What improvements would you suggest?
If the way I tried it originally just worked. It seems it's not working because of a race condition. I ended up just changing the UX so the user has to click a button after signing in to run the mutation. That extra delay it takes for them to see and click the button is enough work around it.
Of course, this UX sucks but I'm in MVP build mode so don't have time to write a new provider.
Or if I could specify an argument to signIn to specify the mutation to run after, along with the mutation arguments
Or if I could call signIn from within a mutation
Yeah, fair