views:

287

answers:

1

Hi folks, I wish to authenticate a user without having the page reloaded, and having the user submit a given form.

However, the problem that I immediately run into here is that the authenticity token typically gets set when the page is reloaded.

I need the authenticity token for the form submission, but i do not have it yet because the page is yet to reload.

I figure this cannot be that rare - anyone has any idea on how to resolve this?

1 idea could be getting rails to pass back the authenticity token after authentication, but i do not know how to access it from the controller

1) not logined user sees form

2) not logined user types in message and submit

3) facebox asking for authentication

4) after authentication, submit form automatically without refreshing

5) //but authenticity token is needed for form submission, which is not there yet

A: 

Hi folks, decided to answer my own question w a potential solution, please feel free to jump in:

in my authentication controller action, i looked at the auth token in the session data, parsed it. The code is as follows:

cookie_data = session.to_hash.clone
auth_token=cookie_data[:_csrf_token]
#pass the auth_token via json, store it in global object, for any future ajax call to use

what do you think?

ming yeow