I'm trying to change my rails APP into an API.
So every respond as te be as JSON
.
So I try to use Devise with an Authentification Token. Since is not supported, I used the gems 'devise_token_auth'
& 'simple_token_authentication'
but with no success.
there is my code for that :
routes.rb
devise_for :users, :controllers => {sessions: 'sessions', registrations: 'registrations'}
sessions_controller.rb
class SessionsController < Devise::SessionsController
respond_to :json
clear_respond_to
after_filter :set_csrf_header, only: [:new, :create]
def create
respond_to do |format|
#format.html { super }
format.json {
warden.authenticate!(:scope => resource_name, recall: "#{controller_path}#failure")
render :status => 200, :json => { :error => "Success" }
}
end
end
def destroy
super
end
protected
def set_csrf_header
response.headers['X-CSRF-Token'] = form_authenticity_token
end
end
At first, The users registration is working properly, but the session login give me a 401
-> and after it redirect me on the session/new
with the message 'You have to login before continue
'
After many attempt to modify, I got a new strange error :
Started POST "/users/sign_in" for 127.0.0.1 at 2015-10-15 11:11:37 +0200
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by SessionsController#create as */*
Parameters: {"email"=>"testemail-1243432342@testmaillocalisem.com", "password"=>"[FILTERED]"}
Completed 500 Internal Server Error in 11ms
ArgumentError (wrong number of arguments (1 for 0)):
/Users/Matthieu/.rvm/gems/ruby-2.2.3/bundler/gems/devise-369a5011f860/app/controllers/devise_controller.rb:28:in `resource_class'
devise_token_auth (0.1.33) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:19:in `set_user_by_token'
devise_token_auth (0.1.33) lib/devise_token_auth/controllers/helpers.rb:115:in `current_user'
devise_token_auth (0.1.33) lib/devise_token_auth/controllers/helpers.rb:103:in `authenticate_user!'
Aucun commentaire:
Enregistrer un commentaire