0

I have to run some code (subscription to an external mailing list) when a new user is created with OmniAuth (any strategy). The setup is pretty much identical to Ryan Bates' screencast:

http://railscasts.com/episodes/241-simple-omniauth?view=asciicast

So far I haven't found a suitable point to hook in the code in the middleware. And when control is returned to the Rails level, the data is passed as user = User.from_omniauth(env["omniauth.auth"]) and nothing indicates whether the user has just been created or not.

A workaround could be a flag on the user which defaults to false and is set to true in session#create. But there has to be a better way, hasn't there? :-)

Thanks for your hints!

svoop
  • 3,318
  • 1
  • 23
  • 41
  • A slightly more elegant workaround: Check the `current_user.created_at` timestamp after the callback to session#create and consider the user as newly created if the timestamp is no older than say 30 seconds. – svoop Nov 15 '12 at 00:35

1 Answers1

0

You can use the :params option to build a URL, like this

omniauth_authorize_path(:user, :facebook, {var: 'value', var2: 'value2'}

and then in the callback you will get in back in the request.env['omniauth.params']

Some examples here - https://github.com/intridea/omniauth/issues/390

Also here- Passing random url params to OmniAuth

Community
  • 1
  • 1
Akshay Rawat
  • 4,714
  • 5
  • 40
  • 65
  • I don't use Devise, so no `omniauth_authorize_path`. I could add params in the config, but it wouldn't help telling after the callback whether the user existed before or not. – svoop Nov 15 '12 at 00:32