PeacockP
Convex Communityβ€’8mo agoβ€’
24 replies
Peacock

Clerk convex logic throws an error every first-time I save while running dev server

6/3/2025, 9:52:40 PM [CONVEX Q(projects:fetchProjects)] Uncaught Error: Can't get current user
    at getCurrentUserOrThrow (../../convex/users.ts:57:9)
    at async handler (../convex/projects.ts:10:15)


I consistently see the function provided on the Clerk+Convex documentation throw on first save, when any convex files have been modified. If I CMD+S again (without file changes) I see the happy message. Odd - I'm just now noticing any time there's an error, the time on save is significantly higher:

βœ” 21:52:06 Convex functions ready! (991.28ms)
6/3/2025, 9:52:06 PM [CONVEX Q(projects:fetchProjects)] Uncaught Error: Can't get current user
at getCurrentUserOrThrow (../../convex/users.ts:57:9)
at async handler (../convex/projects.ts:10:15)

βœ” 21:52:26 Convex functions ready! (394.91ms)
βœ” 21:52:32 Convex functions ready! (379.47ms)
βœ” 21:52:40 Convex functions ready! (947.86ms)
6/3/2025, 9:52:40 PM [CONVEX Q(projects:fetchProjects)] Uncaught Error: Can't get current user
at getCurrentUserOrThrow (../../convex/users.ts:57:9)
at async handler (../convex/projects.ts:10:15)

Any thoughts why? The functionality of the Clerk webhook + seeding the DB works great, annoying to see these errors on the console though πŸ™‚

Below is the code from the docs that's throwing.

export async function getCurrentUserOrThrow(ctx: QueryCtx) {
  const user = await getCurrentUser(ctx);
  if (!user) throw new Error("Can't get current user");
  return user;
}

export async function getCurrentUser(ctx: QueryCtx) {
  const identity = await ctx.auth.getUserIdentity();
  if (identity === null) {
    return null;
  }
  return await userByExternalId(ctx, identity.subject);
}

async function userByExternalId(ctx: QueryCtx, externalId: string) {
  return await ctx.db
    .query("users")
    .withIndex("byExternalId", (q) => q.eq("externalId", externalId))
    .unique();
}
Was this page helpful?