I'm trying to make a GraphQL Mutation (POST) request from a Next.js app.
My request:
mutation loginUser($email: String!, $password: String!) {
loginUser(email: $email, password: $password) {
user {
email
}
exp
token
}
}
I'm getting the error saying:
405 (Method Not Allowed)The response headers:
[{"name":"allow","value":"GET, HEAD"},{"name":"cache-control","value":"no-store, must-revalidate"},{"name":"connection","value":"close"},{"name":"content-encoding","value":"gzip"},{"name":"content-type","value":"text/html; charset=utf-8"},{"name":"date","value":"Tue, 18 Jul 2023 08:11:59 GMT"},{"name":"etag","value":"\"lwb687lsku26b\""},{"name":"transfer-encoding","value":"chunked"},
{"name":"vary","value":"Accept-Encoding"},{"name":"x-powered-by","value":"Next.js"}]
The response headers show that only GET and HEAD are allowed methods. What's the way to go here so I can make
mutationsfrom the app? Do I have to allow POST in the config? Or do I have to make changes in the request?
Never mind. I got it. In case you have a similar problem, here is what was wrong in my case:
In the payload.config.ts file I had the csrf and cors urls as https not http. Localhosts are running under http 😉
I haven't set up the payload, so it took me a while to figure that out. 🤦♂️
Star
Discord
online
Get dedicated engineering support directly from the Payload team.