Files
SanatiLeads/convex/users.ts
2026-02-04 01:05:00 +00:00

27 lines
716 B
TypeScript

import { query } from "./_generated/server";
import { getAuthUserId } from "@convex-dev/auth/server";
export const getCurrent = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (!userId) return null;
return await ctx.db.get(userId);
},
});
export const getCurrentProfile = query({
args: {},
handler: async (ctx) => {
const userId = await getAuthUserId(ctx);
if (!userId) return null;
const user = await ctx.db.get(userId);
if (!user) return null;
const accounts = await ctx.db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect();
return { user, accounts };
},
});