Skip to content

Commit cf4a0d0

Browse files
committed
fix: change to supabaseAdmin to update scripter account
1 parent 3efc5d7 commit cf4a0d0

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

src/lib/server/stripe.server.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Interval, Price, Scripter } from "$lib/types/collection"
44
import type { Database } from "$lib/types/supabase"
55
import type { SupabaseClient } from "@supabase/supabase-js"
66
import Stripe from "stripe"
7+
import { supabaseAdmin } from "./supabase.server"
78

89
export const stripe = new Stripe(STRIPE_KEY, { apiVersion: "2025-08-27.basil", typescript: true })
910

@@ -94,13 +95,7 @@ export async function createCheckoutSession(
9495
return session.url
9596
}
9697

97-
export async function createAccount(
98-
supabase: SupabaseClient,
99-
baseURL: string,
100-
scripter: Scripter,
101-
email: string,
102-
country: string
103-
) {
98+
export async function createAccount(baseURL: string, scripter: Scripter, email: string, country: string) {
10499
let account: Stripe.Response<Stripe.Account>
105100
let accountLink: Stripe.Response<Stripe.AccountLink>
106101

@@ -142,28 +137,18 @@ export async function createAccount(
142137
return
143138
}
144139

145-
console.log("Stripe Account created: ", account, " for ", scripter.id)
146-
147-
const { error: errScripter } = await supabase
148-
.schema("profiles")
149-
.from("scripters")
150-
.update({ stripe: account.id })
151-
.eq("id", scripter.id)
140+
console.log("Stripe Account created: ", account.id, " for ", scripter.id)
152141

153-
if (errScripter) {
154-
console.error(errScripter)
155-
return
156-
}
142+
const promises = await Promise.all([
143+
supabaseAdmin.schema("profiles").from("scripters").update({ stripe: account.id }).eq("id", scripter.id),
144+
supabaseAdmin.schema("profiles").from("balances").update({ stripe: account.id }).eq("id", scripter.id)
145+
])
157146

158-
const { error: errBalances } = await supabase
159-
.schema("profiles")
160-
.from("balances")
161-
.update({ stripe: account.id })
162-
.eq("id", scripter.id)
163-
164-
if (errBalances) {
165-
console.error(errBalances)
166-
return
147+
for (let i = 0; i < promises.length; i++) {
148+
if (promises[i].error) {
149+
console.error(promises[i].error)
150+
return
151+
}
167152
}
168153

169154
try {

src/routes/dashboard/[slug]/stripe/+page.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const actions = {
5252
if (scripter.stripe != scripter.id) return setError(form, "", "Stripe account is already created!")
5353
if (!form.valid) return setError(form, "", "The country code form is not valid!")
5454

55-
const link = await createAccount(supabaseServer, origin, scripter, user.email!, form.data.code)
55+
const link = await createAccount(origin, scripter, user.email!, form.data.code)
5656
if (link) redirect(303, link)
5757
return { form }
5858
},

0 commit comments

Comments
 (0)