Note that there are some explanatory texts on larger screens.

plurals
  1. PODevise logged in but unauthorized
    primarykey
    data
    text
    <p>I have this problem with Devise following these actions:</p> <ul> <li>I sign up a new user (works fine)</li> <li>I confirm the user mail (works fine). At that point I am logged in normally, everything works fine.</li> <li>Now if I log out and try to log back in I get an unauthorized error (401).</li> </ul> <p>Looking at the server logs here what happens:</p> <pre><code>Started POST "/users/sign_in" for 127.0.0.1 at 2012-10-26 10:26:23 +0200 Processing by Users::SessionController#create as JSON Parameters: {"email"=&gt;"olivier.milla@gmail.com", "password"=&gt;"[FILTERED]", "remember_me"=&gt;"0"} WARNING: Can't verify CSRF token authenticity User Load (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'olivier.milla@gmail.com' LIMIT 1 (1.0ms) BEGIN (0.0ms) COMMIT (1.0ms) BEGIN (0.0ms) UPDATE `users` SET `current_sign_in_at` = '2012-10-26 08:26:23', `sign_in_count` = 2, `updated_at` = '2012-10-26 08:26:23' WHERE `users`.`id` = 1 (25.0ms) COMMIT Rendered devise/sessions/create.json.rabl (1.0ms) Completed 200 OK in 135ms (Views: 22.0ms | ActiveRecord: 27.0ms) Started GET "/accounts/new" for 127.0.0.1 at 2012-10-26 10:26:23 +0200 Processing by AccountsController#new as HTML Completed 401 Unauthorized in 0ms </code></pre> <p>As you can see, I am logged in, I even get a view rendered (<code>devise/sessions/create.json.rabl</code>) and right after I get redirected to '/accounts/new' where I am not authorized anymore. I can then try to reach any URL I want and keep getting the unauthorized message.</p> <p>I tried this on a new db (db:reset), I tried cleaning up cookies before log in.</p> <p>Any idea where this behavior may come from?</p> <p>I'm using Devise 2.1.2 with Rails 3.2.8.</p> <p><strong>UPDATE</strong></p> <p>As requested: AccountsController code:</p> <pre><code>class AccountsController &lt; ApplicationController before_filter :authenticate_user! def :index @accounts = current_organization.accounts end def new @account = Account.new(:organization =&gt; current_organization) end def create @account = Account.new(params[:account]) @account.organization = current_organization if @account.save redirect_to :index else #TODO end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload