# How to handle InvalidAuthenticityToken

**URL:** <https://www.ruby-forum.com/t/how-to-handle-invalidauthenticitytoken/165441>\
**Category:** Rails\
**Created:** [April 14, 2009, 12:54am UTC](https://www.ruby-forum.com/t/how-to-handle-invalidauthenticitytoken/165441 "2009-04-14T00:54:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sprite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@sprite](https://www.ruby-forum.com/u/sprite)\
**Post date:** [April 14, 2009, 12:54am UTC](https://www.ruby-forum.com/t/how-to-handle-invalidauthenticitytoken/165441/1 "2009-04-14T00:54:01Z")

</div>

Scenario:

1. Log in a user.
2. Go to a page with a form.
3. Open a new tab and log out the user.
4. Go back to previous tab and submit form.
5. It throws InvalidAuthenticityToken before getting to my login code.  
I need to redirect the user to a log in screen. What’s the best way to  
capture this and handle this?

---

<div class="post-metadata">

**Author:** ![sprite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@sprite](https://www.ruby-forum.com/u/sprite)\
**Post date:** [April 14, 2009, 1:15am UTC](https://www.ruby-forum.com/t/how-to-handle-invalidauthenticitytoken/165441/2 "2009-04-14T01:15:40Z")

</div>

If anyone else is running into this issue here is how I ended up  
handling it

> <https://gist.github.com/94801>
