diff --git a/apps/api/package.json b/apps/api/package.json index 00c518e1..2f092233 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -35,6 +35,7 @@ "pino": "catalog:", "pino-pretty": "catalog:", "thirdweb": "catalog:", + "uuid": "catalog:", "viem": "catalog:" }, "devDependencies": { diff --git a/apps/api/prisma/migrations/20241211082958_profile_email/migration.sql b/apps/api/prisma/migrations/20241211082958_profile_email/migration.sql new file mode 100644 index 00000000..081d5601 --- /dev/null +++ b/apps/api/prisma/migrations/20241211082958_profile_email/migration.sql @@ -0,0 +1,2 @@ +-- DropIndex +DROP INDEX "public"."user_profile_email_key"; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 32b7cbc0..f6184f37 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -72,7 +72,7 @@ model UserProfile { // Fields // Contact - email String? @unique + email String? // TreasureTag tag String? diff --git a/apps/api/src/routes/auth.ts b/apps/api/src/routes/auth.ts index e3d06c6f..31ed9ce9 100644 --- a/apps/api/src/routes/auth.ts +++ b/apps/api/src/routes/auth.ts @@ -7,6 +7,7 @@ import { import type { FastifyPluginAsync } from "fastify"; import { type GetUserResult, defineChain } from "thirdweb"; import { isZkSyncChain } from "thirdweb/utils"; +import { v4 as uuidv4 } from "uuid"; import "../middleware/chain"; import "../middleware/swagger"; @@ -126,18 +127,18 @@ export const authRoutes = }); let userId: string; - let thirdwebUser: GetUserResult; + let thirdwebUser: GetUserResult | null; if (foundUserSmartAccount) { const thirdwebUserDetails = await getThirdwebUser({ ecosystemWalletAddress: foundUserSmartAccount.ecosystemWalletAddress, }); + // TODO: switch to throwing an error when Thirdweb issues are resolved if (!thirdwebUserDetails) { - throwUnauthorizedError( - `No Thirdweb user found for ecosystem wallet ${foundUserSmartAccount.ecosystemWalletAddress}`, + console.warn( + `No user details found for ecosystem wallet ${foundUserSmartAccount.ecosystemWalletAddress}`, ); - return; } userId = foundUserSmartAccount.userId; @@ -168,26 +169,29 @@ export const authRoutes = ecosystemWalletAddress: adminWalletAddress, }); + // TODO: switch to throwing an error when Thirdweb issues are resolved if (!thirdwebUserDetails) { - throwUnauthorizedError( - `No Thirdweb user found for admin wallet ${adminWalletAddress}`, + console.warn( + `No user details found for admin wallet ${adminWalletAddress}`, ); - return; } + const externalUserId = + thirdwebUserDetails?.userId ?? `temp-${uuidv4()}`; + const newUserSmartAccount = await db.userSmartAccount.create({ data: { chainId, address, ecosystemWalletAddress: adminWalletAddress, - // If Thirdweb user ID is present, look for existing user to connect. Otherwise create new user + // Look for existing user to connect, otherwise create a new user user: { connectOrCreate: { where: { - externalUserId: thirdwebUserDetails.userId, + externalUserId, }, create: { - externalUserId: thirdwebUserDetails.userId, + externalUserId, }, }, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 846e11e4..2dc5ca4e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -330,6 +330,9 @@ importers: thirdweb: specifier: 'catalog:' version: 5.74.0(@aws-sdk/client-kms@3.699.0)(@types/react-dom@18.3.1)(@types/react@18.3.13)(encoding@0.1.13)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.7.2)(zod@3.23.8) + uuid: + specifier: 'catalog:' + version: 11.0.3 viem: specifier: 'catalog:' version: 2.21.53(typescript@5.7.2)(zod@3.23.8)