I have this problem with Devise following these actions:
- I sign up a new user (works fine)
- I confirm the user mail (works fine). At that point I am logged in normally, everything works fine.
- Now if I log out and try to log back in I get an unauthorized error (401).
Looking at the server logs here what happens:
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"=>"olivier.milla@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"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
As you can see, I am logged in, I even get a view rendered (devise/sessions/create.json.rabl
) 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.
I tried this on a new db (db:reset), I tried cleaning up cookies before log in.
Any idea where this behavior may come from?
I'm using Devise 2.1.2 with Rails 3.2.8.
UPDATE
As requested: AccountsController code:
class AccountsController < ApplicationController
before_filter :authenticate_user!
def :index
@accounts = current_organization.accounts
end
def new
@account = Account.new(:organization => 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