You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using this code I have a problem in getting the authUser-object working correctly. The error thrown is: Unhandled Rejection (TypeError): Cannot read property 'roles' of undefined
When checking the condition in withAuthorization it first checks using an object authUser = {authUser: {userdata}} and then after some loading, checks again using an object authUser = {userdata}.
This means my conditions only pass if I write an extensive condition like:
const condition = authUser =>
authUser && ((authUser.roles && !!authUser.roles[ROLES.USER])
|| (authUser.authUser.roles && !!authUser.authUser.roles[ROLES.USER]));
This as I cannot be sure the .roles element exists without first checking the depth of the object.
I do the same merging of db and auth object as the example (even double checked with pasting the example code). Is there anyone else experiencing the same thing or know where I might have gone wrong?
The text was updated successfully, but these errors were encountered:
Not really, I just did something similar to what I pasted with a check for the property at different levels within the object. This code for the condition is what was used which looks terrible, but does work.
EDIT: Possibly this can be fixed with the spread operator, but as this was a quick school project I settled once I got it to work for my use case and didn't spend too much time with further investigations on how to make it properly.
Using this code I have a problem in getting the authUser-object working correctly. The error thrown is: Unhandled Rejection (TypeError): Cannot read property 'roles' of undefined
When checking the condition in withAuthorization it first checks using an object authUser = {authUser: {userdata}} and then after some loading, checks again using an object authUser = {userdata}.
This means my conditions only pass if I write an extensive condition like:
const condition = authUser =>
authUser && ((authUser.roles && !!authUser.roles[ROLES.USER])
|| (authUser.authUser.roles && !!authUser.authUser.roles[ROLES.USER]));
This as I cannot be sure the .roles element exists without first checking the depth of the object.
I do the same merging of db and auth object as the example (even double checked with pasting the example code). Is there anyone else experiencing the same thing or know where I might have gone wrong?
The text was updated successfully, but these errors were encountered: