here is my session controller
def create
auth_hash = request.env[‘omniauth.auth’]
if session[:user_id]
# Means our user is signed in. Add the authorization to the user
User.find(session[:user_id]).add_provider(auth_hash)
render :text => "You can now login using
#{auth_hash[“provider”].capitalize} too!"
else
# Log him in or sign him up
auth = Authorization.find_or_create(auth_hash)
# Create the session
session[:user_id] = auth.user.id
render :text => "Welcome #{auth.user.name}!"
end
end
here is my authorization model
def self.find_or_create(auth_hash)
unless auth = find_by_provider_and_uid(auth_hash[“provider”],
auth_hash[“uid”])
user = User.create :name => auth_hash[“user_info”][“name”], :email
=> auth_hash[“user_info”][“email”]
auth = create :user => user, :provider => auth_hash[“provider”],
:uid => auth_hash[“uid”]
end
auth
end
here is my User model
def add_provider(auth_hash)
# Check if the provider already exists, so we don’t add it twice
unless
authorizations.find_by_provider_and_uid(auth_hash[“provider”],
auth_hash[“uid”])
Authorization.create :user => self, :provider =>
auth_hash[“provider”], :uid => auth_hash[“uid”]
end
end
i got the error,
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
it can direct me to login facebook page. How can i get my facebook
token?
I tried using koala,but some method ,it show me undefined method. How to
get the token from auth_hash = request.env[‘omniauth.auth’]
as i test, the code getting all the basic info of the login users
Any helps are appreciated ,I did a lot of testing but I still cant
manage to figure it out.