0
votes

I'm using devise and omniauth in my rails3 app after following the railscast (http://railscasts.com/episodes/235-omniauth-part-1).

I can log in, and I see in my database that the sign_in_count column is being incremented.

However, when user_signed_in? always returns false, and current_user? returns a no method error.

I've seen other answers saying that the problem is caused by rails.js, but I'm not using rails.js.

My controller is

    def create
        omniauth = request.env["omniauth.auth"]

        authentication = Authentication.find_by_provider_and_uid(omniauth['provider'],omniauth['uid'])
        if authentication
            sign_in_and_redirect(:user, authentication.user)

        elsif current_user
            current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
            redirect_to root_url
        else
            user = User.new
            user.apply_omniauth(omniauth)
            if user.save(:validate => false)
                sign_in(:user, user)

                redirect_to root_url
            else
                flash[:notice] = "error creating account"
                redirect_to root_url
            end
        end


    end
1
in your User model, do you have a line saying devise :omniauthable, ...? If not, you need a User model (or if your model is called something else like Person, then you actually want person_signed_in? and current_person)ronalchn
@ronalchn when I add omniauthable, I get a routing error no route matches /auth/facebook I thought the way out of that was to not include omniauthable.pedalpete
Well, I haven't used devise with omniauthable, so I don't know. But I do know that you need to call the devise function (even if you use no arguments for additional modules) in your User model.ronalchn

1 Answers

1
votes

I am going to go out on a limb here, and say that a two year old Railscast might be, well, slightly dated. Several things from both the question, and the comments. First, you have to include Devise's :omniauthable module, or, uhm it won't work. Yes, after that you get no route matches /auth/facebook because you have to tell it where that is.

First I will point you to the write up on the Devise Wiki about setting this up. Second, I will plug a little and give you a recent blog post about using Google OAuth with Devise. Lastly I will leave you with the link to the general Devise Wiki and the fact that there are close to 50 articles on how to do all kinds of awesome things with Devise. These are updated by the community, and generally updated often so they should contain the most recent way of doing things.