Skip to content

Commit

Permalink
Merge pull request #79 from marmelab/fix-auth-provider-getpermissions
Browse files Browse the repository at this point in the history
Fix `authProvider.getPermissions()` should not throw error when not logged in
  • Loading branch information
slax57 authored Oct 29, 2024
2 parents 58924d7 + 420b79e commit 04d2ea8
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/ra-supabase-core/src/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,27 @@ 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')
) {
return;
}

const { data, error } = await client.auth.getUser();
if (error) {
throw error;
}
if (data.user == null) {
return undefined;
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;
},
};

Expand Down

0 comments on commit 04d2ea8

Please sign in to comment.