ahaan
ahaan12mo ago

i am having an issue, this didn't occur

i am having an issue, this didn't occur few days ago
1 Reply
ahaan
ahaanOP12mo ago
so I am following @Web Dev Cody tutorial for file storage. As I create new organization in clerk, it uses webhook to send organization_creation data to convex upon recieving the data, i first check the identity of the existing user before adding him to the organization but the issue is await ctx.auth.getUserIdentity() returns null
// addOrgIdToUser is run as soon as organizationMembership.created is recieved from clerk webhook
export const addOrgIdToUser = internalMutation({
args: {
tokenIdentifier: v.string(),
orgId: v.string()
},
async handler(ctx, args) {
// const user = await getUser(ctx, args.tokenIdentifier);
const identity = await ctx.auth.getUserIdentity();
console.log("getUserIdentity during addOrgIdToUser", args, identity);

if (!identity) {
throw new ConvexError("Unauthenticated call to mutation");
}
const user = await ctx.db
.query("users")
.withIndex("by_tokenIdentifier", (q) =>
q.eq("tokenIdentifier", identity.tokenIdentifier)
)
.first();

if (!user) {
throw new ConvexError("User not found");
}

await ctx.db.patch(user._id, {
orgIds: [...user.orgIds, args.orgId],
});
},
});
// addOrgIdToUser is run as soon as organizationMembership.created is recieved from clerk webhook
export const addOrgIdToUser = internalMutation({
args: {
tokenIdentifier: v.string(),
orgId: v.string()
},
async handler(ctx, args) {
// const user = await getUser(ctx, args.tokenIdentifier);
const identity = await ctx.auth.getUserIdentity();
console.log("getUserIdentity during addOrgIdToUser", args, identity);

if (!identity) {
throw new ConvexError("Unauthenticated call to mutation");
}
const user = await ctx.db
.query("users")
.withIndex("by_tokenIdentifier", (q) =>
q.eq("tokenIdentifier", identity.tokenIdentifier)
)
.first();

if (!user) {
throw new ConvexError("User not found");
}

await ctx.db.patch(user._id, {
orgIds: [...user.orgIds, args.orgId],
});
},
});
never mind i found the issue

Did you find this page helpful?