Bring back ability to find out provider for profile page
This commit is contained in:
@@ -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')) },
|
||||
|
||||
Reference in New Issue
Block a user