kylecorbelli / redux-token-auth

Redux actions and reducers to integrate easily with Devise Token Auth
MIT License
154 stars 80 forks source link

ActionController::InvalidAuthenticityToken in DeviseTokenAuth::RegistrationsController#create #38

Closed peterlawless closed 6 years ago

peterlawless commented 6 years ago

Upon sending a request to the RegistrationsController to sign up, I get a response with a status 422 Unprocessable Entity on account of an invalid (but more likely missing) authenticity token sent with the POST request. My server and client reside on the same domain, so this is not a cross-origin request. Is there a way to hook a rails-generated authenticity token into redux-token-auth for the authentication endpoints? Conversely, what would I be losing by directing the DeviseTokenAuth::RegistrationsController instance to ignore the presence of an authenticity token?

peterlawless commented 6 years ago

My solution was to provide initialValues to my sign up form using ReduxForm:

export default reduxForm({
  form: 'signUp',
  initialValues: { authenticityToken: document.getElementsByName('csrf-token')[0].content}
})(SignUpForm);
josephecombs commented 5 years ago

There is a related discussion here about how to solve this in Rails - it involves protect_from_forgery with: :null_session

https://github.com/lynndylanhurley/devise_token_auth/issues/398