現在AWS(amazon linux2)にRailsアプリをデプロイし、ブラウザでの動作確認をしています。
本番環境でSNS認証を試していると
- Googleアカウント認証は成功
- 確認メールを送信した
というフラッシュメッセージが表示が表示されるのですが、
- GoogleのSNS認証に使用したGoogleアカウントのGmailにメールが送られてこない
状態で原因が全くわかりません(m_ m)
もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m _m)
動作環境
デプロイ先の環境
Rails | AWS |
---|---|
Ruby: 2.4.5 | Amazon linux2 |
Rails: 4.2.11.1 | nginx: 1.16.1 |
Devise: 4.7.1 | EC2、RDS(MySQL) |
ローカル環境
- macOS: Mojave10.14.6
- メール確認gem:
letter_opener_web (1.3.4)
認証関連gem
- omniauth (1.9.0)
- omniauth-facebook (5.0.0)
- omniauth-google-oauth2 (0.8.0)
エラー内容
- エラー表記はない(と思います)
- GoogleのSNS認証に使用したGoogleアカウントのGmailにメールが送られてこない
期待する動作
Google認証を成功させたい
該当しそうなコード
(1/4)db/schema.rb
ruby
1# db/schema.rb 2: 3 create_table "users", force: :cascade do |t| 4 t.string "email", limit: 255, default: "", null: false 5 t.string "encrypted_password", limit: 255, default: "", null: false 6 t.string "reset_password_token", limit: 255 7 t.datetime "reset_password_sent_at" 8 t.datetime "remember_created_at" 9 t.integer "sign_in_count", limit: 4, default: 0, null: false 10 t.datetime "current_sign_in_at" 11 t.datetime "last_sign_in_at" 12 t.string "current_sign_in_ip", limit: 255 13 t.string "last_sign_in_ip", limit: 255 14 t.datetime "created_at", null: false 15 t.datetime "updated_at", null: false 16 t.string "confirmation_token", limit: 255 17 t.datetime "confirmed_at" 18 t.datetime "confirmation_sent_at" 19 t.string "unconfirmed_email", limit: 255 20 t.string "provider", limit: 255 21 t.string "uid", limit: 255 22 t.datetime "soft_destroyed_at" 23 end
(2/4)app/models/user.rb
ruby
1class User < ActiveRecord::Base 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable 6 7 def self.find_for_oauth(auth) 8 user = User.where(uid: auth.uid, provider: auth.provider).first 9 10 unless user 11 user = User.create( 12 uid: auth.uid, 13 provider: auth.provider, 14 email: auth.info.email, 15 # email: User.dummy_email(auth), 16 password: Devise.friendly_token[0, 20] 17 ) 18 end 19 20 user 21 end 22 23 private 24 def self.dummy_email(auth) 25 "#{auth.uid}-#{auth.provider}@example.com" 26 end 27end
(3/4)app/controllers/public/settings/users/omniauth_callbacks_controller.rb
ruby
1# frozen_string_literal: true 2 3class Public::Settings::Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 4 5 def facebook 6 callback_from :facebook 7 end 8 9 def google 10 callback_from :google_oauth2 11 end 12 13 private 14 def callback_from(provider) 15 if provider.to_s == "google_oauth2" 16 provider = "Google" 17 else 18 provider = "Facebook" 19 end 20 21 @user = User.find_for_oauth(request.env['omniauth.auth']) 22 # @user.skip_confirmation! 23 if @user.persisted? 24 flash[:success] = I18n.t('devise.omniauth_callbacks.success', kind: provider.capitalize) 25 sign_in_and_redirect @user, event: :authentication 26 else 27 session["devise.#{provider}_data"] = request.env['omniauth.auth'].except("extra") 28 redirect_to new_user_registration_url, warning: @user.errors.full_messages.join("\n") 29 end 30 end 31end
(4/4)config/environments/production.rb
ruby
1Rails.application.configure do 2 config.cache_classes = true 3 config.eager_load = true 4 config.consider_all_requests_local = false 5 config.action_controller.perform_caching = true 6 config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 7 config.assets.js_compressor = :uglifier 8 config.assets.compile = false 9 config.assets.digest = true 10 config.log_level = :debug 11 config.action_mailer.raise_delivery_errors = true 12 13 config.action_mailer.delivery_method = :smtp 14 config.action_mailer.smtp_settings = { 15 address: 'smtp.gmail.com', 16 port: 587, 17 domain: 'gmail.com', 18 user_name: 'toshihiro.no.ecsite@gmail.com', 19 password: ENV['gmail_password'], 20 authentication: 'plain', 21 enable_starttls_auto: true 22 } 23 config.i18n.fallbacks = true 24 config.active_support.deprecation = :notify 25 config.log_formatter = ::Logger::Formatter.new 26 config.active_record.dump_schema_after_migration = false 27end 28
回答1件
あなたの回答
tips
プレビュー