This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
[Question]: getSession() in API returns null even when session exists #2302
Labels
question
Ask how to do something or how something works
Question 💬
In short, when securing an API route with getSession, any time a page attempts to fetch from the API, getSession returns null but if I go to the API link directly, it works as expected.
To test this, I have a test API route at the path
pages/api/test.js
that callsgetSession({ req })
and returns True if a session is found, False if it isn't.I also have a basic Page component at
pages/test/index.js
. ViagetServerSideProps
, I fetch a response from the API and pass the response as a prop to the Page component. Every time, regardless if I'm signed in or not, the response from the test route is{valid: false}
.However, if I point my browser to
localhost:3000/api/test
, I receive the expected response. Any help here would be appreciated! I'm using Google Sign In with my own MySQL database.How to reproduce ☕️
No response
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
The text was updated successfully, but these errors were encountered: