diff --git a/apps/backend/src/routers/users.ts b/apps/backend/src/routers/users.ts index 73817a84e..83cd38333 100644 --- a/apps/backend/src/routers/users.ts +++ b/apps/backend/src/routers/users.ts @@ -8,6 +8,8 @@ import { mangleDupliateScheduleNames } from 'src/lib/formatting'; import { RDS } from 'src/lib/rds'; import { TRPCError } from '@trpc/server'; import { procedure, router } from '../trpc'; +import { ddbClient } from '$db/ddb'; + const userInputSchema = type([{ userId: 'string' }, '|', { googleId: 'string' }]); @@ -52,8 +54,17 @@ const usersRouter = router({ // Mangle duplicate schedule names data.userData.schedules = mangleDupliateScheduleNames(data.userData.schedules); - await RDS.upsertGuestUserData(db, data) - .catch((error) => console.error('Failed to upsert user data:', error)); + // Await both, but only throw if RDS save fails. + const results = await Promise.allSettled([ + ddbClient.insertItem(data) + .catch((error) => console.error('DDB Failed to save user data:', error)), + RDS.upsertGuestUserData(db, data) + .catch((error) => console.error('RDS Failed to upsert user data:', error)) + ]); + + if (results[1].status === 'rejected') { + throw results[1].reason; + } } ), });