mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
feat(#14): Update signup component to create a stripe customer on signup
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import stripe from 'stripe';
|
||||||
|
import { PUBLIC_STRIPE_SECRET_KEY } from '$env/static/public';
|
||||||
|
|
||||||
let email = '';
|
let email = '';
|
||||||
let password = '';
|
let password = '';
|
||||||
|
|
||||||
// Access the supabase client from the layout data
|
// Access the supabase client from the layout data
|
||||||
export let supabase: any;
|
export let supabase: any;
|
||||||
|
|
||||||
|
const stripeClient = new stripe(PUBLIC_STRIPE_SECRET_KEY);
|
||||||
|
|
||||||
async function signUpNewUser() {
|
async function signUpNewUser() {
|
||||||
try {
|
try {
|
||||||
const { data, error } = await supabase.auth.signUp({
|
const { data, error } = await supabase.auth.signUp({
|
||||||
@@ -12,7 +17,7 @@
|
|||||||
password: password,
|
password: password,
|
||||||
options: {
|
options: {
|
||||||
// Redirect URL after successful sign-up
|
// Redirect URL after successful sign-up
|
||||||
redirectTo: '/welcome'
|
redirectTo: '/profile'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -20,6 +25,21 @@
|
|||||||
throw 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);
|
||||||
|
|||||||
Reference in New Issue
Block a user