@@ -639,20 +639,26 @@ export const deleteListingAction = async (
639639 if ( ! user || ! session ?. access_token ) {
640640 return redirect ( "/sign-in" ) ;
641641 }
642+
643+ const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL ;
644+ const supabaseAnonKey = process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ;
645+
646+ if ( ! supabaseUrl || ! supabaseAnonKey ) {
647+ console . error ( "Missing Supabase client env vars for listing deletion." ) ;
648+ return actionError ( t ( "Errors.generic" ) ) ;
649+ }
650+
642651 // Then continue with the delete listing
643652 try {
644- const response = await fetch (
645- `${ process . env . NEXT_PUBLIC_SUPABASE_URL } /functions/v1/delete-listing` , // Adjust the endpoint as necessary
646- {
647- method : "POST" ,
648- headers : {
649- apikey : process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ! ,
650- Authorization : `Bearer ${ session . access_token } ` ,
651- "Content-Type" : "application/json" ,
652- } ,
653- body : JSON . stringify ( { slug } ) ,
654- }
655- ) ;
653+ const response = await fetch ( `${ supabaseUrl } /functions/v1/delete-listing` , {
654+ method : "POST" ,
655+ headers : {
656+ apikey : supabaseAnonKey ,
657+ Authorization : `Bearer ${ session . access_token } ` ,
658+ "Content-Type" : "application/json" ,
659+ } ,
660+ body : JSON . stringify ( { slug } ) ,
661+ } ) ;
656662
657663 console . log ( "Response status:" , response . status ) ;
658664 console . log ( "Response ok:" , response . ok ) ;
@@ -707,18 +713,25 @@ export const deleteAccountAction = async () => {
707713 return redirect ( "/sign-in" ) ;
708714 }
709715
710- try {
711- const response = await fetch (
712- `${ process . env . NEXT_PUBLIC_SUPABASE_URL } /functions/v1/delete-account` ,
713- {
714- method : "POST" ,
715- headers : {
716- apikey : process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ! ,
717- Authorization : `Bearer ${ session . access_token } ` ,
718- "Content-Type" : "application/json" ,
719- } ,
720- }
716+ const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL ;
717+ const supabaseAnonKey = process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ;
718+
719+ if ( ! supabaseUrl || ! supabaseAnonKey ) {
720+ console . error ( "Missing Supabase client env vars for account deletion." ) ;
721+ return redirect (
722+ `/profile?error=${ encodeURIComponent ( t ( "deleteAccountFailed" ) ) } `
721723 ) ;
724+ }
725+
726+ try {
727+ const response = await fetch ( `${ supabaseUrl } /functions/v1/delete-account` , {
728+ method : "POST" ,
729+ headers : {
730+ apikey : supabaseAnonKey ,
731+ Authorization : `Bearer ${ session . access_token } ` ,
732+ "Content-Type" : "application/json" ,
733+ } ,
734+ } ) ;
722735
723736 console . log ( "Response status:" , response . status ) ;
724737 console . log ( "Response ok:" , response . ok ) ;
0 commit comments