Fetch method Not Allowed, but works in other clients
I need to do a GET to have a list, I need the authoritation with cookie.
When I use Rest Client or Thunder Client I have the 200. great
But from my defineEventHandler in my server/api in Nuxt 3, when I do the fetch I got the specific "Request failed with status 405". And GET works both in the 2 other clients. What do you see?
15 Replies
even the smallest defineEventHandler !!!
and with an easy one it works!
start by using builtin $fetch
I do get a 405 aswell. that means that get req is now allowed. does it need auth? if yes who configured it to be 405 lol
also i like double api api.fixer.net/api x)
405 means that the HTTP method is not allowed. When you do a
fetch
or $fetch
(which I would suggest) without configuration, it performs a GET request. However, when visiting https://api.fxer.net/api/trial
in the browser, you get an 405 Method not allowed.
This means you likely need to do a POST or check their documentation.
Read more about $fetch
https://nuxt.com/docs/api/utils/dollarfetchNuxt
$fetch · Nuxt Utils
Nuxt uses ofetch to expose globally the $fetch helper for making HTTP requests.
yes it does need auth, but in the mock clients Im passing them
thanks! I'm on it!!
I read that $fetch is recomended in the clientside
Im doing it for the server side
with $ stills does 405 but in a better way
How is my nuxt server different from the clients I used?
in Rest Client this works soooooo well:
my idea is that its bad devs returning 405 on unauthenticated. are you sure you have the cookies available?
Im including the credentials: "include", plus I'm able to access the list when I use the client (Rest Client)
if I am not authenticated it not even the client access
well there is a difference in how youre authenticating in the client and in your code. how are you doing it in your client?
but no worries I changed my plan, now Im calling a public API, Id try to finish the test with https://restcountries.com/v3.1/all
youd need to make sure that the right cookie is avaibale with the right values
in nuxt 3 server, I use credentials include
that is not an answer
sometimes after it gives 405 I got requestIncludesCredentials: true,
is true, Im using a module
"dependencies": {
"next-auth": "^4.21.1",
"nuxt": "^3.10.3",
"vue": "^3.4.19",
"vue-router": "^4.3.0"
},
"devDependencies": {
"@sidebase/nuxt-auth": "^0.6.7"
next-auth and @sidebase/nuxt-auth, for session they work really well
just before the fetch I get server session
do I need axios?