1

ログインシステムの工夫でomniauthとfacebookプラグインを実装しています。

ただし、同じ facebook アカウントが別のトークンを返すようですuid

Rails でこのような状況に対処するにはどうすればよいでしょうか。

私の新しく設計された方法には悪い副作用がありますか?

システムにログインする唯一の方法として、facebook omniauth のみを使用する予定です。

オリジナルのユーザー作成方法

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
  end
end

新しく設計されたメソッド

def self.from_omniauth(auth)
  where(email: auth.email).first_or_create do |user|
    user.provider = auth.provider
    user.uid = auth.uid
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
  end
end

サンプル文書

{
  "_id": ObjectId("55bf803b69702d0603000000"),
  "email": "sample@gmail.com",
  "encrypted_password": "5a2U.62pm6.fsdfdsfdsvNrf.akZ4la45ixpgqB20n6uu",
  "sign_in_count": 4,
  "provider": "facebook",
  "uid": "113569521332134112514",
  "reset_password_token": null,
  "reset_password_sent_at": null,
}

{
  "_id": ObjectId("55c157a5506f638652000000"),
  "email": "sample@gmail.com",
  "encrypted_password": "$sdfgg,so51lkpe7P5DDKwz3hTrqFE7MsfRw0lEa",
  "sign_in_count": 1,
  "provider": "facebook",
  "uid": "10000014141261376741",
}
4

0 に答える 0