Since two days i tried to make Login with Facebook on ruby on rails using devise but it returns me NULL as email's value. I read many articles on stackoverflow but a lot of them are from years ago and none have worked for me. Thanks you for helping.
Here is the message in my console when i choose my facebook account
Asked
Active
Viewed 63 times
-1

Chaldrak
- 1
- 1
-
Please provide enough code so others can better understand or reproduce the problem. – Community Oct 17 '21 at 16:45
-
Hello. Thanks, but I found a solution. Indeed during my authorization request, since there is no email associated with the facebook account that I was using for login, it returned me NULL. Finally I managed with the username which I get correctly. – Chaldrak Oct 18 '21 at 06:55
1 Answers
0
def self.from_omniauth(auth)
unless auth.info.email
auth.info.email = "#{auth.info.name.split(' ').join}@facebook.com"
end
user = User.where("email= ?", auth.info.email).first
puts auth.info.picture
puts auth.info.name
puts auth.info.email
if user
return user
else
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0, 20]
user.name = auth.info.name # assuming the user model has a name
# user.image = auth.info.image # assuming the user model has an image
# If you are using confirmable and the provider(s) you use validate emails,
# uncomment the line below to skip the confirmation emails.
user.skip_confirmation!
user.uid = user.uid
user.provider = user.provider
end
end

Chaldrak
- 1
- 1