#Store user mutation in production

9 messages · Page 1 of 1 (latest)

tidal turret
#

When calling the store user mutation in production, it seems to fail. It works fine when i test it in development. Has anyone come across such an issue and managed to solve it.

elder crown
#

any more details on the failure?

tidal turret
#

this is the function. the user is already stored in the db after sign up through webhook call. I'm trying to update the user table and add a firebase uuid

#

export const storeUser = mutation({
args: {
firebaseUserId: v.string(),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new Error('Unauthenticated');
}

// check if user is already stored
const user = await ctx.db
  .query('users')
  .withIndex('by_token_identifier', (q) =>
    q.eq('tokenIdentifier', identity.tokenIdentifier)
  )
  .unique();

if (user === null) {
  throw new Error('No user found');
}

const userId = await ctx.db.patch(user._id, {
  email: identity.email,
  firebaseUserId: args.firebaseUserId,
});

return userId;

},
});

#

Uncaught Error: No user found is what am getting in at prod. During local development it works just fine

mighty niche
#

How are you creating users? Have you checked your Convex dashboard to see whether the user document is in the table?

tidal turret
#

Yes. The user exists in the dashboard. I invoked a webhook intergrated with clerk

#

The functions fails to find the stored user

mighty niche
#

In your production dashboard? You can switch between "dev" and "prod" up top.