mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-15 12:03:49 +00:00
feat(#22): Add handling for sign up db events
This commit is contained in:
@@ -12,40 +12,57 @@
|
|||||||
|
|
||||||
async function signUpNewUser() {
|
async function signUpNewUser() {
|
||||||
try {
|
try {
|
||||||
const { data, error } = await supabase.auth.signUp({
|
await supabaseSignUp().then((data) => {
|
||||||
email: email,
|
console.log(data);
|
||||||
password: password,
|
createStripeCustomer(data);
|
||||||
options: {
|
|
||||||
// Redirect URL after successful sign-up
|
|
||||||
redirectTo: '/account'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
// Handle success (optional)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Sign up error:', error.message);
|
console.error('Sign up error:', error.message);
|
||||||
// Handle error
|
// 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>
|
</script>
|
||||||
|
|
||||||
<form class="card-body">
|
<form class="card-body">
|
||||||
|
|||||||
Reference in New Issue
Block a user