From 420b79eb1833048fb2a873a58e7f9dc29fa320f5 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 29 Oct 2024 09:32:33 +0100 Subject: [PATCH] authProvider.getPermissions should leave early if there is no permissions policy --- packages/ra-supabase-core/src/authProvider.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/ra-supabase-core/src/authProvider.ts b/packages/ra-supabase-core/src/authProvider.ts index d08622a..2f634a7 100644 --- a/packages/ra-supabase-core/src/authProvider.ts +++ b/packages/ra-supabase-core/src/authProvider.ts @@ -157,14 +157,14 @@ export const supabaseAuthProvider = ( return Promise.resolve(); }, async getPermissions() { - if ( - window.location.pathname === '/set-password' || - window.location.hash.includes('#/set-password') - ) { + if (typeof getPermissions !== 'function') { return; } - // Users are on the forgot-password page, nothing to do + // No permissions when users are on the set-password page + // or on the forgot-password page. if ( + window.location.pathname === '/set-password' || + window.location.hash.includes('#/set-password') || window.location.pathname === '/forgot-password' || window.location.hash.includes('#/forgot-password') ) { @@ -172,18 +172,12 @@ export const supabaseAuthProvider = ( } const { data, error } = await client.auth.getUser(); - if (error) { - return; - } - if (data.user == null) { + if (error || data.user == null) { return; } - if (typeof getPermissions === 'function') { - const permissions = await getPermissions(data.user); - return permissions; - } - return undefined; + const permissions = await getPermissions(data.user); + return permissions; }, };