coneC
Convex Community5mo ago
2 replies
cone

BetterAuth User Type Safety

Any idea why the user returned from this function is of type "any"? Shouldn't it be typed according to the better auth user schema?


async getAuthUser(ctx: RunQueryCtx & { auth: ConvexAuth }) {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
return null;
}
const doc = await ctx.runQuery(this.component.lib.findOne, {
model: "user",
where: [
{
field: "userId",
value: identity.subject,
},
],
});
if (!doc) {
return null;
}
// Type narrowing
if (!("emailVerified" in doc)) {
throw new Error("invalid user");
}
const { id: _id, ...user } = doc;
return user;
}
Was this page helpful?