uschtwill / rails_rss_aggregator

MIT License
3 stars 1 forks source link

Bug: Log-out method not working in API #8

Open uschtwill opened 9 years ago

uschtwill commented 9 years ago

@alvinkatojr

Any ideas, why this is not working?

This is how it should work in theory:

Do a DELETE-type http request to the URL https://salty-sierra-8863.herokuapp.com/api/sessions/, passing the auth-token for the user that is to be logged out. The controller checks, if that auth token is in the user table and deletes it. This results in the user who that auth token belonged to being 'logged out'.

This is the request to the API:

curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE https://salty-sierra-8863.herokuapp.com/api/sessions/\?auth_token\=JRYodzXgrLsk157ioYHf

This is the relevant controller#action:

  def destroy
    warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
    # current_user.update_column(:authentication_token, nil)
    current_user.authentication_token = nil
    current_user.save!
    if current_user.authentication_token == nil
      render :status => 200,
             :json => { :success => true,
                        :info => "Successfully logged out: #{current_user.email}",
                        :data => {} }
    else
      render :status => 200,
              :json => { :success => false,
                        :info => "Didn't work! Tried to log out: #{current_user.email}",
                        :data => {} }
    end
  end

This is the response body:

{ "success": false, "info": "Didn't work! Tried to log out: uschtrinw@gmail.com", "data": {} }