Replies: 2 comments 1 reply
-
|
It might be that the API call is getting cached. Try passing a
fetch(`https://...`, { cache: 'no-store' })That being said, this is a bit of an unnecessary setup. You I can understand this is a bit annoying, so perhaps you want to use a |
Beta Was this translation helpful? Give feedback.
-
|
I also experienced the same thing. My API literally returns response 500, my browser also says so, but my nextjs run by npm always says the response status is 200. Even Google Gemini says it's impossible, but yeah, it happens. The funnier thing is, my database is off, but Nextjs magically says like, "Well, the response is ok, so keep arguing with Google Gemini to see who'll win." |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Fairly new to nextjs, and I've come across an issue when trying to fetch an api. The API itself is fairly simple and checks if there is a session (user is logged in) and then returns a JSON with a GET. (Im using nextauth for authentication.
This is the getGoal/route.ts API file:
If i access this code in my browser http://localhost:3000/api/getGoal, it returns the 401 message with User not logged in, if im not logged in and it returns the json if I am logged in. However, if i then try and fetch this API in my page.tsx:
And if I console.log the data.status, it always returns a status code of 200 and always shows the data. I think I'm missing something here, but I just can't seem to wrap my head around it. Again, I am fairly new to Nextjs and React in general.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions