前提・実現したいこと
【omniauth-facebook】を用いたログイン機構の実装。
上記を実装中なのですがリンクをクリックしても、
デバイスで用意されたサインアップページにリダイレクトされてしまいます...
発生している問題・エラーメッセージ
ページ中央のsign in facebook をクリックしても、
下記のdeviseによって用意されたサインアップページにリダイレクトされてしまいます...
エラーメッセージすら出ず、ページがリダイレクトされてしまいます。
コード情報
【User.rb】
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :omniauthable def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = auth.info.email # user.update_attribute(:email, auth.info.email) user.password = Devise.friendly_token[0,20] user.name = auth.info.name # assuming the user model has a name user.image = auth.info.image # assuming the user model has an image # If you are using confirmable and the provider(s) you use validate emails, # uncomment the line below to skip the confirmation emails. # user.skip_confirmation! end end end
【omniauth_callbacks_controller.rb】
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @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
【routes.rb】
Rails.application.routes.draw do devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } get 'users/new' root 'static_pages#home' get 'static_pages/terms' get 'static_pages/home' end
【サーバーログ】
Started GET "/users/auth/facebook" for 119.224.169.247 at 2019-05-15 11:15:07 +0000 I, [2019-05-15T11:15:07.630826 #4023] INFO -- omniauth: (facebook) Request phase initiated. Started GET "/users/auth/facebook" for 119.224.169.247 at 2019-05-15 11:15:08 +0000 I, [2019-05-15T11:15:08.340298 #4023] INFO -- omniauth: (facebook) Request phase initiated. Started GET "/users/auth/facebook/callback?code=〜〜〜〜〜コード〜〜〜〜〜" for 119.224.169.247 at 2019-05-15 11:15:09 +0000 I, [2019-05-15T11:15:09.049863 #4023] INFO -- omniauth: (facebook) Callback phase initiated. Processing by Users::OmniauthCallbacksController#facebook as HTML Parameters: {"code"=>"〜〜〜コード〜〜〜, "state"=>"〜〜〜ステート〜〜〜〜"} User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."provider" = ? AND "users"."uid" = ? ORDER BY "users"."id" ASC LIMIT ? [["provider", "facebook"], ["uid", "589989758173505"], ["LIMIT", 1]] (0.1ms) begin transaction (0.0ms) rollback transaction Redirected to https:(ドメイン名).vfs.cloud9.us-east-2.amazonaws.com/users/sign_up Completed 302 Found in 156ms (ActiveRecord: 0.3ms)
上記のように、それぞれリクエストフェーズ、コールバックフェーズには至っているものの、
最終的にrollbackされてしまいます...
どなたかご助言を頂けませんでしょうか。
あなたの回答
tips
プレビュー