Develop + Omniauth + remember_me

There seems to be some confusion about how to remember how I work with Omniauth.

According to this wiki, you need to have the following in your OmniauthCallbacksController:

remember_me(user)

On the other hand, according to this issue you just need to do this:

user.remember_me = true

Also, if remember_me is set to true according to this , you just need to add the following to your User.rb

def remember_me
  true
end

Not sure which one is the official answer, and all three don't work for me. It works only for Chrome on Mac, but not for Firefox Mac and Chrome Windows. Not sure what is going on.

My code is as follows:

# -*- encoding : utf-8 -*-
class OmniauthCallbacksController < Devise::OmniauthCallbacksController

    include Devise::Controllers::Rememberable

    def all
        omniauth = request.env["omniauth.auth"]
        auth = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
        if auth

            auth.update_with_omniauth omniauth
            auth.save!

            # ???
            remember_me auth.user
            auth.user.remember_me = true

            if user_signed_in?
                redirect_back_or settings_path(current_user)
            else
                sign_in_and_redirect auth.user, event: :authentication
            end
        else
            if user_signed_in?
                current_user.build_auth(omniauth).save!
                redirect_back_or settings_path(current_user)
            else
                session["devise.omniauth"] = omniauth.except('extra')
                redirect_to new_user_registration_url
            end
        end
    end

    alias_method :facebook, :all
    alias_method :twitter, :all

end
+4
1

.

. true, , , .

, , , cookie. , cookie , .

+1

All Articles