Please help!
I’m working with Supabase and use the new “Data&API” Tab, so I dont have any plugins installed.
A user can have multiple tenants and therefore I store the tenants ID in my JWT (app_metadata).
I use a invoke edge function in order to switch the tenant and store the tenant_id in the JWT - BUT - after that I need to refresh the session in order to use that new tenant id but I simply can’t refresh the session as the new native Supabase integration doesn’t give the function “refresh”.
If I now use the Supabase auth plugin in order to get the refresh session, I can’t access the invoke edge function anymore. it’s a nightmare.
also I tried custom JS in order to refresh but I always get an error as apparently weweb changed a lot of its editor architecture?!
this is the JS code:
// Get the Supabase integration instance
const supabase = wwLib.getIntegration(‘supabase’).instance;
// Force a session refresh to retrieve the updated JWT with new tenant claims
const { data, error } = await supabase.auth.refreshSession();
if (error) {
wwLib.log.error(‘Failed to refresh session:’, error.message);
throw error;
}
return data.session;
(its from we webs ai, but similar to gemini and gpt)
the “bulletproof js that should DEFINITELY work (haha ): ) is this one:
try {
// 1. Locate the Supabase Auth instance
// WeWeb typically uses ‘supabaseAuth’ or ‘supabase’ as the plugin ID
const supabasePlugin = wwLib.wwPlugins.supabaseAuth || wwLib.wwPlugins.supabase;
if (!supabasePlugin || !supabasePlugin.instance) {
throw new Error('Supabase integration not found. Please ensure the Supabase Auth plugin is installed.');
}
const supabase = supabasePlugin.instance;
// 2. Force a session refresh
// This calls the Supabase API to exchange the refresh token for a new access token
// containing the updated 'app_metadata' (the new tenant claims).
const { data, error } = await supabase.auth.refreshSession();
if (error) {
wwLib.log.error('Supabase Refresh Error:', error.message);
return { success: false, error: error.message };
}
// 3. Update the global session context in WeWeb
// This ensures that subsequent requests use the new JWT
return {
success: true,
session: data.session,
accessToken: data.session.access_token
};
} catch (err) {
wwLib.log.error(‘Workflow JS Error:’, err.message);
throw err;
}
Anyone can help me with this one? feels like the new weweb + Supabase is not too recommendable.