@@ -116,7 +116,9 @@ export const fetchOrCreateSpaceDirect = async (
116116 const error = spaceValidator ( data ) ;
117117 if ( error !== null ) return asPostgrestFailure ( error , "invalid space" ) ;
118118 data . url = data . url . trim ( ) . replace ( / \/ $ / , "" ) ;
119- const urlSlug = data . url . replaceAll ( / \W / g, "" ) ;
119+ // Distinguish local, or various supabase branches
120+ const supabaseUrlFirstFragment = new URL ( process . env . SUPABASE_URL || 'http://null' ) . hostname . split ( '.' ) [ 0 ] ;
121+ const urlSlug = supabaseUrlFirstFragment + ":" + data . name . replaceAll ( / \W / g, "" ) ;
120122 const supabase = createSingletonClient ( urlSlug ) ;
121123 if ( ! supabase ) return asPostgrestFailure ( "No database" , "" ) ;
122124 const session = await supabase . auth . getSession ( ) ;
@@ -127,14 +129,14 @@ export const fetchOrCreateSpaceDirect = async (
127129 . select ( )
128130 . eq ( "url" , data . url )
129131 . maybeSingle ( ) ;
130- if ( result . error )
132+ if ( result . error && result . status >= 500 )
131133 return result ;
132134 if ( result . data !== null )
133135 return result as PostgrestSingleResponse < SpaceRecord > ;
134136 // space does not exist, or not visible from this account;
135137 // logout to be sure
136138 console . warn ( `Creating a space while already logged in as ${ session . data . session . user . email } ; logging out` ) ;
137- await supabase . auth . signOut ( ) ;
139+ await supabase . auth . refreshSession ( ) ; // this will clear an invalid session
138140 }
139141 // If it does not exist, create it
140142 const result2 : FunctionsResponse < SpaceRecord > =
0 commit comments