Race condition when calling mutation after sign in
At the end of my onboarding flow I sign the user in anonymously and then save their onboarding responses to a "userProfile" table
await signIn("anonymous");
await saveOnboardingData({
name: userName,
selectedColor: selectedColor || "grey",
});Inside the mutation I am doing the following
export const saveOnboardingData = mutation({
args: {
name: v.string(),
selectedColor: v.string(),
},
handler: async (ctx, args) => {
const userId = await getAuthUserId(ctx);
if (!userId) throw new Error("Not authenticated");
const userData = {
userId,
name: args.name,
selectedColor: args.selectedColor,
};
await ctx.db.insert("userProfiles", userData);
},
});But calling this results in the "Not authenticated" error.
If I put in a 1 second delay between the sign in and the mutation call it works fine, but of course thats a hack that could fall apart.
