Skip to content

Commit

Permalink
fix: fixed crash when user does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jun 26, 2024
1 parent 3a4f180 commit 433a6a7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/adapters/supabase/helpers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 433a6a7

Please sign in to comment.