login error - with graphql

default discord avatar
taongaB
7 months ago
8

Please help. I get this message error message when I attempt to login in with correct credentials in production: "Cannot read properties of undefined (reading 'includes')" . However, on localhost, everything works just fine.



my axios query option:



let variables = {


email: email,


password: password


}


const options = {


method: 'POST',


url:

${api_graph_v2}

,


headers: {


'content-type': 'application/json',


},


withCredentials: true,


credentials:'include',


data: {


query:

mutation loginUser($email:String!,$password:String!){ loginUser(email:$email,password:$password){ token, exp, user{ id email fName lName } } }

,


variables: variables


}


};

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    Can you share the full stack trace for this error:



    "Cannot read properties of undefined (reading 'includes')"
  • default discord avatar
    taongaB
    7 months ago

    Sure:



    [04:21:29] ERROR (payload): TypeError: Cannot read properties of undefined (reading 'includes')


    at Object.read (/home/jelastic/ROOT/dist/collections/Users.js:47:40)


    at promise (/home/jelastic/ROOT/node_modules/payload/dist/fields/hooks/afterRead/promise.js:145:71)


    at /home/jelastic/ROOT/node_modules/payload/dist/fields/hooks/afterRead/traverseFields.js:7:50


    at Array.forEach (<anonymous>)


    at traverseFields (/home/jelastic/ROOT/node_modules/payload/dist/fields/hooks/afterRead/traverseFields.js:6:12)


    at afterRead (/home/jelastic/ROOT/node_modules/payload/dist/fields/hooks/afterRead/index.js:21:41)


    at login (/home/jelastic/ROOT/node_modules/payload/dist/auth/operations/login.js:120:44)


    at processTicksAndRejections (node:internal/process/task_queues:96:5)


    at async graphqlMiddleware (/home/jelastic/ROOT/node_modules/express-graphql/index.js:125:26)



    So, for some reason, my access filter does not work in production:



    {


    label: "birth day",


    name: 'bd',


    type: 'text',


    access: {


    read: ({ req: { user } }) => { if (user) { if (user.roles.includes('admin')) { return true } } return false },


    }


    },

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    yep - that's definitely the problem



    a user doesn't

    have

    roles, and you are accessing

    roles.includes

    unsafely



    if you fix that, you should be golden

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.