Get OAuth Access Token
Unanswered
Klaas posted this in #help-forum
KlaasOP
Hi, 👋
What is the best practice way to save an access_token returned from a OAuth post request, I need to do multiple different requests and the access_token expires after 3600 seconds of inactivity.
My first thought was to use a useContext for this. Would this be considered best practice?
What is the best practice way to save an access_token returned from a OAuth post request, I need to do multiple different requests and the access_token expires after 3600 seconds of inactivity.
My first thought was to use a useContext for this. Would this be considered best practice?
8 Replies
Blanc de Hotot
Are you using next-auth to make your request?
KlaasOP
@Blanc de Hotot not yet
@Blanc de Hotot the authorization is not really a login, so next-auth seemed a bit much to me, or am i completly wrong about that?
Blanc de Hotot
No, I was just trying to get context on the application so I can hopefully provide better advice
KlaasOP
i can send you a link to the api docs if that would be helpful?
Blanc de Hotot
If you need the access_token on the client, I suggest storing it as a cookie. If it's for server-use only, you should use a useEffect to access changes in the access_token (that way when/if you implement rotating refresh tokens it should stay stable).
I've had not so much success with useContext in Next, and find that more 'basic' react components perform better. I'm no expert though, it's just been my experience
KlaasOP
mmh oke let me check it out, thanks!