Sahag98
Sahag98
CCConvex Community
Created by Sahag98 on 11/15/2024 in #support-community
GetUserIdentity null
Hi there, I have a list of queries that run for it's corresponding page in my nextjs 14 web app. Inside each query I have a getUser hook that will check the identity and return the user associated with it:
import { QueryCtx } from "@/convex/_generated/server";

export async function GetUser(ctx: QueryCtx) {
const identity = await ctx.auth.getUserIdentity();

if (!identity) {
throw new Error("Unauthenticated call to mutation");
}
const user = await ctx.db
.query("users")
.withIndex("byExternalId", (q) => q.eq("externalId", identity.subject))
.unique();
if (!user) {
throw new Error("Unauthenticated user call");
}

return user;
}
import { QueryCtx } from "@/convex/_generated/server";

export async function GetUser(ctx: QueryCtx) {
const identity = await ctx.auth.getUserIdentity();

if (!identity) {
throw new Error("Unauthenticated call to mutation");
}
const user = await ctx.db
.query("users")
.withIndex("byExternalId", (q) => q.eq("externalId", identity.subject))
.unique();
if (!user) {
throw new Error("Unauthenticated user call");
}

return user;
}
However there are instances where the identity is sometimes null, therefore throwing that error and interrupting the user. How can I implement this in a better way? I feel like I'm doing something wrong here... Thank you!
5 replies
CCConvex Community
Created by Sahag98 on 10/11/2023 in #support-community
I'm getting this error in the console when I try to sign in with Clerk
Failed to authenticate: "No auth provider found matching the given token", check your server auth config I have successfully added all the env variables to the convex dashboard such as the issuer domain and I am able to get the user to sign but im still getting this error and when I try to checkuseridentity in a mutation I'm getting null
8 replies