grumpy-cyan•3y ago
Cannot invoke an object which is possibly 'undefined'
Hi everyone, can anyone help me with this? I trying to integrate Access Control with Supabase and when I'm trying invoke authProvider.getPermissions it throws an error.
here is my code for getPermissions
getPermissions: async () => {
const user = await supabaseClient.auth.getUser();
if (user) {
return user.data.user?.role;
}
const { data } = await supabaseClient.rpc('get_my_claim', {
claim: 'role',
});
return Promise.resolve(data);
},
4 Replies
Hey @franzdev! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
----------------------
It seems like you're trying to use
getPermissions with Supabase and facing an issue. Based on the information extracts provided, I can see that there's a slight difference in the implementation of getPermissions in your code compared to the example provided in the refine-pixels-6 blog post (https://refine.dev/blog/refine-pixels-6/).
Here's the adjusted getPermissions() method from the blog post:
In your code, you're using await supabaseClient.auth.getUser() instead of supabaseClient.auth.user(). Also, you're trying to access user.data.user?.role, which is not present in the example provided.
Try updating your getPermissions method to match the example provided in the blog post and see if it resolves the issue.
----------------------<@619660544319684609> kapa.ai is still learning and improving, please let us how it did by reacting below
conscious-sapphire•3y ago
Hey @franzdev,
You can try like that:
Because
getPermission is optional on authProvider type.grumpy-cyanOP•3y ago
Hey @salihozdemir Thank you so much