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
+43 -26
View File
@@ -12,40 +12,57 @@
async function signUpNewUser() {
try {
const { data, error } = await supabase.auth.signUp({
email: email,
password: password,
options: {
// Redirect URL after successful sign-up
redirectTo: '/account'
}
await supabaseSignUp().then((data) => {
console.log(data);
createStripeCustomer(data);
});
if (error) {
throw error;
}
const customer = await stripeClient.customers.create({
email
});
const response = await supabase
.from('user')
.update({
customer_id: customer.id
})
.match({
id: data.user.id
});
console.log(response);
// 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({
email: email,
password: password,
options: {
// Redirect URL after successful sign-up
redirectTo: '/account'
}
});
console.log(data, error);
if (error) {
throw error;
}
return data;
}
async function createStripeCustomer(data: any) {
console.log('createStripeCustomer');
await stripeClient.customers
.create({
email
})
.then(async (customer) => {
console.log(customer);
const response = await supabase
.from('customers')
.update({
customer_id: customer.id
})
.match({
id: data.user.id
});
console.log(response);
});
}
</script>
<form class="card-body">