0

I'm using OmniAuth as a way to let users link their social networks into a system. So I have the common match '/auth/:provider/callback', to: 'authentications#create' in my routes.

This is fine, and I store that info for a particular user in a table. However, I have another way of using OmniAuth that should not overlap this one. The users can use a call to /auth/facebook to log into the system and therefore I should not just store that information into the authentications table, but also log the user into the system.

On the other hand, a user that is logged in might just want to link his/her Facebook account without logging in but the call will be done to the same /auth/facebook. So my question is: How can I discover where that call to auth/facebook was done from?

Nobita
  • 23,519
  • 11
  • 58
  • 87

1 Answers1

0

An idea would be to have a before_filter in your authentications controller, which simply checks if the user is already signed-in. #sign_in? might look something like this:

def sign_in?
 if @oauth.provider == 'facebook'
   if current_user?
     # then lets associate this facebook credentials with the logged-in user.
   else
     # user isn't logged in, so let's do that
     sign_in(@authentication.account)
   end
 end
end
osahyoun
  • 5,173
  • 2
  • 17
  • 15
  • this is a good idea. the only thing here is that I deal with Facebook sign up in another action of another controller. I will see. – Nobita Feb 10 '12 at 23:46