SupabaseS
Supabase6mo ago
Noroup

I am able to fetch the profile, not able to update it. What am I doing wrong here?

As the title suggests. What am I doing wrong here? Here is my code

        let { data: profiles, error: acctError } = await supabase
        .from("profiles")
        .select("*")
        .eq("id", cart[0].user_id)

        if(acctError || profiles.length == 0){
            apiResp = "Error fetching customer profile";
            return {
                statusCode: respStatusCode,
                body: JSON.stringify(apiResp)
            }
        }

        if(profiles[0].STRIPE_customerid != null){
            STRIPE_custID = profiles[0].STRIPE_customerid
        }
        else{
            console.log("Updating customer ID")
            const customer = await stripe.customers.create();
            STRIPE_custID = customer.id

            const { data: updateResult, error: acctUpdateError} = await supabase
            .from('profiles')
            .update({STRIPE_customerid: 'test'})
            .eq('id', profiles[0].id)


            console.log("Logging update result")
            console.log(updateResult)
            console.log(acctUpdateError)

            if(acctUpdateError ){
                apiResp = "Error updating customer ID";
                return {
                    statusCode: respStatusCode,
                    body: JSON.stringify(apiResp)
                }
            }
        }
Was this page helpful?