From 433a6a7c3f19b2722df75e7b826bc6b8e0244a1e Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 26 Jun 2024 12:29:50 +0200 Subject: [PATCH] fix: fixed crash when user does not exist --- src/adapters/supabase/helpers/wallet.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/adapters/supabase/helpers/wallet.ts b/src/adapters/supabase/helpers/wallet.ts index 505ff6b..7949315 100644 --- a/src/adapters/supabase/helpers/wallet.ts +++ b/src/adapters/supabase/helpers/wallet.ts @@ -84,6 +84,7 @@ export class Wallet extends Super { const { data: userData, error: userError } = await this.supabase .from("users") .insert([{ id: user.id, location_id: locationId /* other fields if necessary */ }]) + .select() .single(); if (userError) { @@ -95,7 +96,7 @@ export class Wallet extends Super { private async _checkIfWalletExists(userData: UserRow) { if (userData.wallet_id === null) { - throw new Error("Wallet ID is null."); + return { data: null, error: null }; } const { data, error } = await this.supabase.from("wallets").select("*").eq("id", userData.wallet_id).maybeSingle(); @@ -149,7 +150,7 @@ export class Wallet extends Super { address: address, }; - const { data: walletInsertData, error: walletInsertError } = await this.supabase.from("wallets").insert(newWallet).single(); + const { data: walletInsertData, error: walletInsertError } = await this.supabase.from("wallets").insert(newWallet).select().single(); if (walletInsertError) throw walletInsertError; return walletInsertData as WalletRow;