Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authProvider.getPermissions() should not throw error when not logged in #79

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
fzaninotto marked this conversation as resolved.
Show resolved Hide resolved
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
Loading