Replies: 2 comments
-
What you are trying to do is not possible.
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your comments! Would you please be able to expand on option 1 as I don't really understand what you mean. You are saying that I am already doing some of it correctly which is to pass the jwt token from the server to the session and have access to it there. But I don't know what you mean by doing it client-side ie: I don't know if you mean I should rather use React useEffect or something like that instead of getStaticProps? Sorry, I am new to Next.js and still trying to wrap my head around everything as I am used to React app. I would prefer to do it on the client because it will be in the dashboard area where when records are deleted etc. it should update the state and then filter out the deleted record, updating the list in 'real time'. UPDATE: I have tried something though which seems to work actually. Just not sure if I am doing it correctly... I am also looking into SWR as that might be a good option here as well.
|
Beta Was this translation helpful? Give feedback.
-
I am using "credentials" as my authentication method because I have an external API. When I was using React app, upon successful login, the response would be a JWT token. So, I still need this token from the server in order to make requests to the API as I need to send it to the header.
So, for my auth provider I do a post request to the server and get the JWT token as a response. I then needed to modify the callback to add it to the session (I am also not sure if what I am doing here is correct)
This seems to work okay because I now have the token from the server in my session and can access it. However, on a page where I need to use it, I can't do it. I get an error that basically says getStaticProps can't run because 'session' isn't defined. If I try to move useSession() out of the component I get an error and if I try move getStaticProps into the component I get an error because I can't do that.
Beta Was this translation helpful? Give feedback.
All reactions