undefined method skip_confirmation! - devise, omniauth

devise, omniauth, ruby-on-rails

Solution

So if I'm right (not 100% secure), you need to declare that your model has the module confirmable, add the confirmable module:

   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable

And make sure that you have the fields for the confirmable module on your users table, you should have the fields confirmation_token and confirmed_at

If you don't have those fields, check on this answer how to add them.

Problem

Trying to set up facebook authentication using devise, omniauth (including facebook-omniauth) on an app hosted on heroku. Call to facebook API works, but I do not manage to skip the confirmation step after callback. I followed the github tutorial on omniauth : https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview and also read and tried to implement this : Devise skip_confirmation! not working But I keep getting the following error in my heroku log : ``` NoMethodError (undefined method `skip_confirmation!') ``` Here is how my devise.rb looks : ``` config.omniauth :facebook, "API_KEY", "API_SECRET" {:strategy_class => OmniAuth::Strategies::Facebook, :scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}} ``` Here is my omniauth_callbacks_controller.rb : ``` class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end end ``` Here is my user.rb model : ``` def self.find_for_facebook_oauth(auth, signed_in_resource=nil) user = User.where(:provider => auth.provider, :uid => auth.uid).first unless user user = User.new(name:auth.extra.raw_info.name, provider:auth.provider, uid:auth.uid, email:auth.info.email, password:Devise.friendly_token[0,20], ) user.skip_confirmation! user.save end user end ``` Thanks for your help !

Original source

Related problems