Workaround for Next Auth x unstable_cache behaviour.
Unanswered
Satin Angora posted this in #help-forum
Satin AngoraOP
Nighty!
I am currently working in a project that uses a lot of server actions and I noticed someday they weren't cached the way the fetch api were by default.
I searched a lot and I tried to use React Query, but its invalidation didn't work the way it should. I did more searches after that and concluded it was better to find another alternative.
Then I found the unstable_cache in the documentation and it appears to be exactly what I was looking for. The only problem is: at the moment you wrap your action in the cache method, you can no longer use the headers() or cookies() methods. That got me really bad because I'm using Next Auth at my platform and the method that retrieved the information of the authenticated user uses these methods.
The documentation highlights that if I need to access data from those methods, I should pass it as a parameter to the action, but how can I make it somehow frontend can't modify the session data and keep a pattern that is easy to replicate in other actions if needed?
Hope someone can help me with this
I am currently working in a project that uses a lot of server actions and I noticed someday they weren't cached the way the fetch api were by default.
I searched a lot and I tried to use React Query, but its invalidation didn't work the way it should. I did more searches after that and concluded it was better to find another alternative.
Then I found the unstable_cache in the documentation and it appears to be exactly what I was looking for. The only problem is: at the moment you wrap your action in the cache method, you can no longer use the headers() or cookies() methods. That got me really bad because I'm using Next Auth at my platform and the method that retrieved the information of the authenticated user uses these methods.
The documentation highlights that if I need to access data from those methods, I should pass it as a parameter to the action, but how can I make it somehow frontend can't modify the session data and keep a pattern that is easy to replicate in other actions if needed?
Hope someone can help me with this