feat(#22): Add handling for sign up db events

This commit is contained in:
Josh Creek
2024-07-16 20:01:03 +01:00
parent 0539afb16e
commit 18772364f7
+27 -10
View File
@@ -12,6 +12,20 @@
async function signUpNewUser() { async function signUpNewUser() {
try { try {
await supabaseSignUp().then((data) => {
console.log(data);
createStripeCustomer(data);
});
// Handle success (optional)
} catch (error: any) {
console.error('Sign up error:', error.message);
// Handle error
}
}
async function supabaseSignUp() {
console.log('supabaseSignUp');
const { data, error } = await supabase.auth.signUp({ const { data, error } = await supabase.auth.signUp({
email: email, email: email,
password: password, password: password,
@@ -20,17 +34,25 @@
redirectTo: '/account' redirectTo: '/account'
} }
}); });
console.log(data, error);
if (error) { if (error) {
throw error; throw error;
} }
const customer = await stripeClient.customers.create({ return data;
email }
});
async function createStripeCustomer(data: any) {
console.log('createStripeCustomer');
await stripeClient.customers
.create({
email
})
.then(async (customer) => {
console.log(customer);
const response = await supabase const response = await supabase
.from('user') .from('customers')
.update({ .update({
customer_id: customer.id customer_id: customer.id
}) })
@@ -39,12 +61,7 @@
}); });
console.log(response); console.log(response);
});
// Handle success (optional)
} catch (error: any) {
console.error('Sign up error:', error.message);
// Handle error
}
} }
</script> </script>