Bring back ability to find out provider for profile page

This commit is contained in:
2026-01-13 15:09:10 -06:00
parent 8f71a22d2b
commit 09b191eb64
5 changed files with 34 additions and 17 deletions

View File

@@ -25,13 +25,25 @@ const getUserById = async (
if (!user) throw new ConvexError('User not found.');
return user;
};
const isSignedIn = async (ctx: QueryCtx): Promise<Doc<'users'> | null> => {
const userId = await getAuthUserId(ctx);
if (!userId) return null;
const getAuthAccountById = async (ctx: QueryCtx, userId: Id<'users'>) => {
const user = await ctx.db.get(userId);
if (!user) return null;
return user;
if (!user) throw new ConvexError('User not found.');
const authAccount = await ctx.db
.query('authAccounts')
.withIndex('userIdAndProvider', (q) => q.eq('userId', userId))
.first();
if (!authAccount) throw new ConvexError('Auth account not found');
return authAccount;
};
export const getUserProvider = query({
args: { userId: v.optional(v.id('users')) },
handler: async (ctx, args) => {
const userId = args.userId ?? (await getAuthUserId(ctx));
if (!userId) return null;
const authAccount = await getAuthAccountById(ctx, userId);
return authAccount.provider;
},
});
export const getUser = query({
args: { userId: v.optional(v.id('users')) },