Facebook перенаправляет на страницу регистрации после аутентификации пользователя Rails - PullRequest
0 голосов
/ 07 декабря 2018

Я интегрирую вход в Facebook с помощью устройства, и после того, как Facebook разрешает получать ваши данные, он перенаправляет вас на страницу регистрации.Вот мой код:

class ApplicationController < ActionController::Base
 protect_from_forgery with: :exception
 before_action :authenticate_user!
 before_action :configure_permitted_parameters, if: :devise_controller?

def configure_permitted_parameters
 devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :description, :photo ])

 devise_parameter_sanitizer.permit(:account_update, keys: [:username, :first_name, :last_name, :description, :photo ])
end

end

Контроллер обратного вызова

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
 def facebook
  @user = User.from_omniauth(request.env["omniauth.auth"])

if @user.persisted?
  sign_in_and_redirect @user, :event => :authentication #this will throw         if @user is not activated
  set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
  session["devise.facebook_data"] = request.env["omniauth.auth"]
  redirect_to new_user_registration_url
 end

end

def failure
  redirect_to root_path
end
end

И моя пользовательская модель

def self.new_with_session(params, session)
super.tap do |user|
  if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
    user.email = data["email"] if user.email.blank?
  end
 end
end

 def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  user.email = auth.info.email
  user.password = Devise.friendly_token[0,20]
  user.first_name = auth.info.name   # assuming the user model has a name
  user.image = auth.info.image # assuming the user model has an image
end
end

Я бы очень признателен за дополнительный взгляд на то, что я 'Я делаю неправильно, или где я что-то упускаю.Спасибо!

1 Ответ

0 голосов
/ 08 декабря 2018

Вам нужно добавить этот столбец для провайдера и uid в таблицу пользователей, я думаю, что rails не может соответствовать вашему пользователю:

rails g migration add_provider_and_uid_to_users provider:string uid: string

И попробуйте написать мне ответ сервера rails, который может помочьвыяснить источник ошибки

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...