Skip to content

Instantly share code, notes, and snippets.

@mfifth
Last active February 21, 2017 00:53
Show Gist options
  • Select an option

  • Save mfifth/dd8ac957f9d8b4bfe5405ca44c76c76d to your computer and use it in GitHub Desktop.

Select an option

Save mfifth/dd8ac957f9d8b4bfe5405ca44c76c76d to your computer and use it in GitHub Desktop.
def self.from_omniauth(auth)
@user = User.find(self.id)
unless User.where(provider: auth.provider, uid: auth.uid).first
@user.provider = auth.provider
@user.uid = auth.uid
@user.save
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, notice: "You have successfully connected Facebook."
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment