Skip to content

Problem with the authUser object in withAuthorization/Authentication #22

Open
@JonatanLindstrom

Description

@JonatanLindstrom

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions