Access component props in data fetching method (eg: static getInitialProps) #10940
Unanswered
michel-fresh
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I have an app that uses
withAuthSync
from the [next-cookie-auth example](https://github.com/zeit/next.js/blob/canary/examples/with-cookie-auth).
This works to ensure all of my wrapped components have user data at render, but how do I access user data when I'm doing data fetching? For instance, I want to pass along user data (like a user id, or a role or type etc, in my case it's an array of languages the user can translate) while calling
getInitialProps
.My question is: how do I make use of component props in a data fetching call? That function only receives a context object, which has no props. Is the issue that this function is running on the server and therefore has no notion of component props? What's the recommended way to use user data, or any props for that matter, when fetching data for components?
What I'm doing now feels hacky, I essentially check if we are in the browser, if so, get the user data from local storage, otherwise, check for a cookie token then and call a function to refetch user data from the db (this only happens when the refresh button is used, from what I can tell).
Any help appreciated!
Thank you
Beta Was this translation helpful? Give feedback.
All reactions