Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:31:48+00:00 2026-06-10T18:31:48+00:00

I am getting undefined method `[]’ for nil:NilClass NoMethodError in Users::OmniauthCallbacksController#facebook undefined method `[]’

  • 0

I am getting undefined method `[]’ for nil:NilClass

 NoMethodError in Users::OmniauthCallbacksController#facebook

  undefined method `[]' for nil:NilClass

  Rails.root: /home/krishna/picer
  Application Trace | Framework Trace | Full Trace

  app/models/user.rb:13:in `find_for_facebook_oauth'
  app/controllers/users/omniauth_callbacks_controller.rb:4:in `facebook'

This is my user.rb code

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable:omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable,
     :omniauthable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token['extra']['user_hash']
if user = User.find_by_email(data["email"])
  user
else # Create a user with a stub password.
  User.create(:email => data["email"], :password => Devise.friendly_token[0,20])
  end
end

 def self.new_with_session(params, session)
  super.tap do |user|
    if data = session["devise.facebook_data"] && session["devise.facebook_data"]  ["extra"]["user_hash"]
    user.email = data["email"]
   end
  end
 end
end

And omniauth callbacks controller code

 class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
 def facebook
 # You need to implement the method below in your model
 @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

if @user.persisted?
  flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
  sign_in_and_redirect @user, :event => :authentication
else
  session["devise.facebook_data"] = env["omniauth.auth"]
  redirect_to new_user_registration_url
 end
end

def passthru
  render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
 end

end

I am getting error line four user.rb I used a example for this https://github.com/ryanatwork/devise-omniauth

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:31:50+00:00Added an answer on June 10, 2026 at 6:31 pm

    You should get the user email with access_token['info']['email'] instead of access_token['extra']['user_hash']['email'].

    I don’t think the data in access_token['extra'] follows a convention like the rest, so you should be extra careful and test if the property you’re trying to access exists. It’s not that important if you only have one provider, but it is if you have several of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

undefined method 'key?' for nil:NilClass This is the error I am getting while going
I getting the error undefined method `update_attributes' for nil:NilClass when using Sinatra with MongoMapper.
I am getting undefined method `accept' for nil:NilClass error while running db:migrate. My configuration
I keep getting a undefined method 'comments' for nil:NilClass in my create method when
I'm getting a no method error in my Static_pages#home: undefined method `exists?' for Registry
I'm getting the error: undefined method `model_name' for NilClass:Class when trying to call the
I'm creating some basic OO scripts using MySQLi and getting an Undefined Method error
I'm getting this error : undefined method `has_many' for #<Formtastic::SemanticFormBuilder:0xb410d4c> It work when I
I am getting the following error Fatal error: Call to undefined method MongoCollection::command() in
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.