-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to refresh CSRF token? #1615
Comments
@Talha345 nothing has changed around this for many years. I think there is something specific to your app. |
@justin808 Could be but do you have any suggestion on how to deal with this scenario. I will try to explain my specific scenario in detail:
NOTE: In older versions of Rails, a single CSRF token was used for each session but since recent versions, we have a new CSRF token for each new request. |
Solution for anyone having the same issue:
Took inspiration from https://stackoverflow.com/questions/33941864/rails-automatically-update-csrf-token-for-repeat-json-request |
@Talha345 @Judahmeek @alexeyr-ci Should this go into the docs? If so, could one of you submit a PR and I'll merge it. |
I am using
ReactOnRails.authenticityToken();
to get the CSRF token generated bycsrf_meta_tags
. The problem is that when I send first request, it works fine as the token is valid. Whenever I send any subsequent API request, it returns the previously invalidated CSRF token and therefore I getActionController::InvalidAuthenticityToken
. How can I refresh the CSRF token after each API request?The text was updated successfully, but these errors were encountered: