Update stuff so we can pass build hopefully
This commit is contained in:
@@ -35,36 +35,42 @@ export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
|
|||||||
const getUserById = async (
|
const getUserById = async (
|
||||||
ctx: QueryCtx,
|
ctx: QueryCtx,
|
||||||
userId: Id<'users'>,
|
userId: Id<'users'>,
|
||||||
): Promise<Doc<'users'>> => {
|
): Promise<Doc<'users'> | null> => {
|
||||||
const user = await ctx.db.get(userId);
|
const user = await ctx.db.get(userId);
|
||||||
if (!user) throw new ConvexError('User not found.');
|
return user ?? null;
|
||||||
return user;
|
|
||||||
};
|
};
|
||||||
const getAuthAccountById = async (ctx: QueryCtx, userId: Id<'users'>) => {
|
const getAuthAccountById = async (ctx: QueryCtx, userId: Id<'users'>) => {
|
||||||
const user = await ctx.db.get(userId);
|
const user = await ctx.db.get(userId);
|
||||||
if (!user) throw new ConvexError('User not found.');
|
if (!user) return null;
|
||||||
const authAccount = await ctx.db
|
const authAccount = await ctx.db
|
||||||
.query('authAccounts')
|
.query('authAccounts')
|
||||||
.withIndex('userIdAndProvider', (q) => q.eq('userId', userId))
|
.withIndex('userIdAndProvider', (q) => q.eq('userId', userId))
|
||||||
.order('desc')
|
.order('desc')
|
||||||
.first();
|
.first();
|
||||||
if (!authAccount) throw new ConvexError('Auth account not found');
|
return authAccount ?? null;
|
||||||
return authAccount;
|
};
|
||||||
|
|
||||||
|
const getCurrentUserId = async (ctx: QueryCtx) => {
|
||||||
|
try {
|
||||||
|
return await getAuthUserId(ctx);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
export const getUserProvider = query({
|
export const getUserProvider = query({
|
||||||
args: { userId: v.optional(v.id('users')) },
|
args: { userId: v.optional(v.id('users')) },
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const userId = args.userId ?? (await getAuthUserId(ctx));
|
const userId = args.userId ?? (await getCurrentUserId(ctx));
|
||||||
if (!userId) return null;
|
if (!userId) return null;
|
||||||
const authAccount = await getAuthAccountById(ctx, userId);
|
const authAccount = await getAuthAccountById(ctx, userId);
|
||||||
return authAccount.provider;
|
return authAccount?.provider ?? null;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getUser = query({
|
export const getUser = query({
|
||||||
args: { userId: v.optional(v.id('users')) },
|
args: { userId: v.optional(v.id('users')) },
|
||||||
handler: async (ctx, args) => {
|
handler: async (ctx, args) => {
|
||||||
const userId = args.userId ?? (await getAuthUserId(ctx));
|
const userId = args.userId ?? (await getCurrentUserId(ctx));
|
||||||
if (!userId) return null;
|
if (!userId) return null;
|
||||||
return getUserById(ctx, userId);
|
return getUserById(ctx, userId);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user