Authenticate facebook with omniauth

I am adding Facebook authentication using omniauth to my application according to Ryan Bates screencast

There was a problem with the create function in the authentication controller. the create function should handle the facebook callback (which seems nice).

Error in the log file:

NoMethodError method (undefined`authentications' for nil: NilClass)

The error refers to this line in the create function in the authentication controller:

current_user.authentications.find_or_create_by_provider_and_uid (auth ['provider'], auth ['uid'])

What do you think is the problem?

Thanks,

Oded

+4
source share
3 answers

The problem is that you were not logged in when trying to authenticate, so current_user is zero. Log in and then authenticate and you will be redirected to the authentication index page. So he did it at railscast. In the next episode, he addresses a user who is not logged in.

+4
source

Your current_user is zero, so when you try to access authentication on a nil object, you get the error message that you see.

You need to fix your current_user method.

+1
source

I had the same problem, but it was solved. The reason this error occurs is because the AuthenticationControllers action creates an action in order to be currently registered by the user and tries to find or create a new authentication for this user. As with an authentication attempt without first logging in with a username and password, the current_user variable will be zero.

Follow the link to solve the problem http://railscasts.com/episodes/236-omniauth-part-2?view=asciicast

0
source

Source: https://habr.com/ru/post/1343013/


All Articles