Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

login error - with graphql

default discord avatar
taongab2 years ago
3

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
    2 years ago

    Can you share the full stack trace for this error:



    "Cannot read properties of undefined (reading 'includes')"
  • default discord avatar
    taongab2 years 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
    2 years 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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.