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
}
};
Can you share the full stack trace for this error:
"Cannot read properties of undefined (reading 'includes')"
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 },
}
},
yep - that's definitely the problem
a user doesn't
haveroles, and you are accessing
roles.includes
unsafely
if you fix that, you should be golden
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.