Skip to content

Problem with the authUser object in withAuthorization/Authentication #22

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

Open
JonatanLindstrom opened this issue Sep 5, 2019 · 2 comments

Comments

@JonatanLindstrom
Copy link

JonatanLindstrom commented Sep 5, 2019

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?

@MincePie
Copy link

MincePie commented Jan 9, 2020

Did you find a solution?

I'm stuck trying to read the name attribute from the user collection from the authUser listener.

@JonatanLindstrom
Copy link
Author

JonatanLindstrom commented Jan 11, 2020

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.

const condition = authUser => authUser && ((authUser.roles && !!authUser.roles[ROLES.ADMIN]) || (authUser.authUser && authUser.authUser.roles && !!authUser.authUser.roles[ROLES.ADMIN]));

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants