From 112fd55ea79ace241e1315edeb940751a5bf5016 Mon Sep 17 00:00:00 2001 From: Gabriel Brown Date: Sun, 21 Jun 2026 22:32:02 -0500 Subject: [PATCH] Update stuff so we can pass build hopefully --- packages/backend/convex/auth.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/backend/convex/auth.ts b/packages/backend/convex/auth.ts index 57d17e6..ca64e53 100644 --- a/packages/backend/convex/auth.ts +++ b/packages/backend/convex/auth.ts @@ -35,36 +35,42 @@ export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({ const getUserById = async ( ctx: QueryCtx, userId: Id<'users'>, -): Promise> => { +): Promise | null> => { const user = await ctx.db.get(userId); - if (!user) throw new ConvexError('User not found.'); - return user; + return user ?? null; }; const getAuthAccountById = async (ctx: QueryCtx, userId: Id<'users'>) => { const user = await ctx.db.get(userId); - if (!user) throw new ConvexError('User not found.'); + if (!user) return null; const authAccount = await ctx.db .query('authAccounts') .withIndex('userIdAndProvider', (q) => q.eq('userId', userId)) .order('desc') .first(); - if (!authAccount) throw new ConvexError('Auth account not found'); - return authAccount; + return authAccount ?? null; +}; + +const getCurrentUserId = async (ctx: QueryCtx) => { + try { + return await getAuthUserId(ctx); + } catch { + return null; + } }; export const getUserProvider = query({ args: { userId: v.optional(v.id('users')) }, handler: async (ctx, args) => { - const userId = args.userId ?? (await getAuthUserId(ctx)); + const userId = args.userId ?? (await getCurrentUserId(ctx)); if (!userId) return null; const authAccount = await getAuthAccountById(ctx, userId); - return authAccount.provider; + return authAccount?.provider ?? null; }, }); export const getUser = query({ args: { userId: v.optional(v.id('users')) }, handler: async (ctx, args) => { - const userId = args.userId ?? (await getAuthUserId(ctx)); + const userId = args.userId ?? (await getCurrentUserId(ctx)); if (!userId) return null; return getUserById(ctx, userId); },