I use the gem 'omniauth-twitter' to let my user login to my app. Then I can use their name and profile image from twitter on my app.
The problem I am facing is that when a user update its name or image on twitter, it doesn't update on my app.
Here is my config:
app/controllers/omniauth_callbacks_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user = User.from_omniauth(request.env["omniauth.auth"])
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
end
app/models/user.rb
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.name = auth.info.nickname
user.image = auth["info"]["image"].sub("_normal", "")
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"]) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
end
I did not suceed to update user attributes. Any ideas following my configuration to do this ? thanks.