Even though I've specified method: "POST" node-fetch still uses get #1671
Answered
by
flamekiller22
flamekiller22
asked this question in
Q&A
-
This is the code I'm using: async authorize(credentials, req) {
const payload = {
email: credentials.email,
password: credentials.password
}
const res = await fetch(`${process.env.API_URL}auth/login`, {
method: 'post',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
}
});
const user = await res.json()
if (!res.ok || user?.method === "GET") {
console.log('Auth response:', user);
throw new Error('Invalid Username & Password combination!');
}
if (res.ok && user) {
return user;
}
console.log('Auth response:', user);
return null
}
|
Beta Was this translation helpful? Give feedback.
Answered by
flamekiller22
Nov 11, 2022
Replies: 2 comments 1 reply
-
And yes I tried using |
Beta Was this translation helpful? Give feedback.
0 replies
-
Found the problem. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
flamekiller22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found the problem.
Turns out when following a redirect it does not honour the method and just uses GET.
Not sure if this is expected behaviour or a bug so leaving this in Q&A for now.