The application I'm working on is on React and Rails. I'm using devise
and I wanted to add a button to resend the confirmation link.
I added it in my React js file as follows:
<a className="btn btn-secondary" onClick={this.resendConfirmation.bind(this)}>Resend Confirmation Link</a>
resendConfirmation() {
API.get('users/confirmation', {}, function(res) {
this.setState(res);
}.bind(this));
}
But when I click on the button I get an error 400 Bad Request {confirmation_token: ["can't be blank"]}
Obviously it is because of the following code in my confirmations_controller.rb
def show
resource_class.confirmation_token = User.confirmation_token
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
# Automatically login user after confirmation.
sign_in(resource)
render :status => 200, :json => resource.to_json
else
render :status => 400, :json => {error: true, message: resource.errors.messages}
end
end
Over here it doesn't find a confirmation_token
and so it sends the 400 Bad Request
.
Currently I'm storing the user's confirmation_token
in the database, I wanted to know if there is any way I can sent it as a part of my request via react?
Aucun commentaire:
Enregistrer un commentaire