0

I want to build RailsAPI with facebook login, so I chose devise_token_auth. I followed the instruction and run rails g devise_token_auth:install User auth, my routes look like

routes.rb

Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

So it is the stuff that comes from generator. I registered my app at facebook for developers, store the facebook-key and facebook-secret in env file. When I hit the first time localhost:3000/auth/facebook it redirectem me to facebook auth popup, I clicked the button and then the error comes.

enter image description here

Should I override the controller from devise with my own? How to do that? Or there are any other solutions?

I would like to mention that is my first time building API with rails.

Daniel
  • 153
  • 2
  • 12

1 Answers1

0

I had solved the problem when rewrite assign_provider_attrs

route.rb mount_devise_token_auth_for 'User', at: 'auth' , controllers: { omniauth_callbacks: 'authentication_rails/omniauth_callbacks' }

controllers/concerns/authentication_rails/omniauth_callbacks_controller

module AuthenticationRails class OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController protected # break out provider attribute assignment for easy method extension def assign_provider_attrs(user, auth_hash) if auth_hash['provider'] == 'facebook' user.assign_attributes({ nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], image: auth_hash['info']['image'], email: auth_hash['info']['email'] }) else super end end end end

wuyuedefeng
  • 61
  • 1
  • 4