ElfinslayerE
Convex Community2y ago
7 replies
Elfinslayer

getUserIdentity() returning null

Hey all, I'm building an app and I've come across an issue where I have a currentUser function that uses the standard ctx.auth.getUserIdentity() method, but it seems to be returning null despite being logged in. I'm successfully using the function in another function with no issues. This is called as a query on the frontend. Code:

export const currentUser = query({
  handler: async (ctx) => {
    const identity = await ctx.auth.getUserIdentity();

    console.log(identity);

    const user = await ctx.db
      .query("users")
      .withIndex("by_token", (q) =>
        q.eq("tokenIdentifier", identity?.tokenIdentifier ?? "")
      )
      .unique();

    if (!user) throw new Error("Invalid current user");

    return user;
  },
});

console.log there to confirm it's null.
image.png
Was this page helpful?