@@ -281,77 +281,6 @@ export async function getSubscriptionStatus() {
281281 return subscription ;
282282}
283283
284- export async function createCheckoutSession ( priceId : string ) {
285- const supabase = await createClient ( ) ;
286-
287- const { data : { user } , error : userError } = await supabase . auth . getUser ( ) ;
288-
289- if ( userError || ! user ) {
290- throw new Error ( 'User not authenticated' ) ;
291- }
292-
293- const basePath = process . env . NEXT_PUBLIC_BASE_PATH || '' ;
294- const response = await fetch ( `${ basePath } /api/create-checkout-session` , {
295- method : 'POST' ,
296- headers : {
297- 'Content-Type' : 'application/json' ,
298- } ,
299- body : JSON . stringify ( {
300- priceId,
301- userId : user . id ,
302- email : user . email ,
303- } ) ,
304- } ) ;
305-
306- if ( ! response . ok ) {
307- throw new Error ( 'Failed to create checkout session' ) ;
308- }
309-
310- const { sessionId } = await response . json ( ) ;
311- return { sessionId } ;
312- }
313-
314- export async function cancelSubscription ( ) {
315- const supabase = await createClient ( ) ;
316-
317- const { data : { user } , error : userError } = await supabase . auth . getUser ( ) ;
318-
319- if ( userError || ! user ) {
320- throw new Error ( 'User not authenticated' ) ;
321- }
322-
323- const basePath = process . env . NEXT_PUBLIC_BASE_PATH || '' ;
324- const response = await fetch ( `${ basePath } /api/cancel-subscription` , {
325- method : 'POST' ,
326- headers : {
327- 'Content-Type' : 'application/json' ,
328- } ,
329- body : JSON . stringify ( {
330- userId : user . id ,
331- } ) ,
332- } ) ;
333-
334- if ( ! response . ok ) {
335- throw new Error ( 'Failed to cancel subscription' ) ;
336- }
337-
338- // Update the profile subscription status
339- const { error : updateError } = await supabase
340- . from ( 'profiles' )
341- . update ( {
342- subscription_status : 'canceled' ,
343- } )
344- . eq ( 'user_id' , user . id ) ;
345-
346- if ( updateError ) {
347- throw new Error ( 'Failed to update subscription status' ) ;
348- }
349-
350- revalidatePath ( '/' , 'layout' ) ;
351- revalidatePath ( '/settings' , 'layout' ) ;
352- revalidatePath ( '/plans' , 'layout' ) ;
353- }
354-
355284export async function checkSubscriptionPlan ( ) {
356285 const supabase = await createClient ( ) ;
357286 const { data : { user } } = await supabase . auth . getUser ( ) ;
0 commit comments