DavisD
Convex Community11mo ago
10 replies
Davis

I'm encountering an issue where, after

I'm encountering an issue where, after logging in with Google, the
currentUser query (which relies on getAuthUserId) consistently returns null on the first dashboard load. I've verified the login is successful. However, a page reload resolves the issue. Could this be a bug related to the initial authentication state?

// dashboard
 const user = await context.queryClient.fetchQuery({
   ...convexQuery(api.users.currentUser, {}),
   staleTime: 0,
   gcTime: 0,
  })
  console.log("auth route", user)
  if (!user) {
   throw redirect({ to: "/sign-in" });
  }

// convex/users.ts
import { getAuthUserId } from "@convex-dev/auth/server";
import { query } from "./_generated/server";

export const currentUser = query({
  args: {},
  handler: async (ctx) => {
    const userId = await getAuthUserId(ctx);
    if (userId === null) {
      return null;
    }
    return await ctx.db.get(userId);
  },
});
Was this page helpful?