How to handle expired token while making external api call in nextjs? #66874
Unanswered
Gopal-creater
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
-
Summary
Below is my signin function, whenthe signin is successfull i am setting cookie.
Whenever i make external api calls, i am sending the beare token with request then the backend will check for the verification of token and if expired throws 401 error, Below is my apiRequest reusable function
I am calling apiRequest from serve action below
Additional information
If the 401 error comes in apiRequest then i simply want to delete the cookie which i previously set during signin and also want to redirect the user to login.
How can i achieve that?
The error i am getting is headers can only be set using server actions or api route handlers I have tried both approaches but no luck. Please help me.
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions