Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 Unauthorized with rails 4.1.4 and devise 3.2.4 #3164

Closed
victorsosa opened this issue Aug 21, 2014 · 2 comments
Closed

401 Unauthorized with rails 4.1.4 and devise 3.2.4 #3164

victorsosa opened this issue Aug 21, 2014 · 2 comments

Comments

@victorsosa
Copy link

using rails 4.1.4, devise 3.2.4 and mongoid 4.0

I have this issue when I login; I am redirecting the user after login to stores/dashboard;
for some reason I got the 401 Unauthorized. Also I had to include the patch for the user model.
Due a reason authenticate_user is not working properly

Controller

class StoresController < ApplicationController

  before_action :authenticate_user!, :except => [:index]

  def index
  end

  def dashboard
  end
end

routes.rb

  get 'stores/dashboard' => 'stores#dashboard', :as => 'user_root'
  root :to => 'stores#index' , :as => 'stores'
Started POST "/users/sign_in" for 127.0.0.1 at 2014-08-21 09:48:59 -0400
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"n7t7mLISBOGMYWxJWzw8qNHwP3y9HGR+79P0vmEodEg=", "user"=>{"email"=>"victornsosa@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
  MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=>1} runtime: 0.7452ms
  MOPED: 127.0.0.1:27017 QUERY        database=prometheus_development collection=users selector={"$query"=>{"email"=>"victornsosa@gmail.com"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.6844ms
  MOPED: 127.0.0.1:27017 UPDATE       database=prometheus_development collection=users selector={"_id"=>BSON::ObjectId('53f5eded6265743c0a010000')} update={"$set"=>{"last_sign_in_at"=>2014-08-21 13:32:55 UTC, "current_sign_in_at"=>2014-08-21 13:48:59 UTC, "sign_in_count"=>9}} flags=[]
                         COMMAND      database=prometheus_development command={:getlasterror=>1, :w=>1} runtime: 0.5836ms
Redirected to http://localhost:3000/stores/dashboard
Completed 302 Found in 88ms


Started GET "/stores/dashboard" for 127.0.0.1 at 2014-08-21 09:48:59 -0400
Processing by StoresController#dashboard as HTML
  MOPED: 127.0.0.1:27017 QUERY        database=prometheus_development collection=users selector={"$query"=>{"_id"=>"[{\"$oid\"=>\"53f5eded6265743c0a010000\"}]"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.3786ms
**Completed 401 Unauthorized in 2ms**


Started GET "/users/sign_in" for 127.0.0.1 at 2014-08-21 09:48:59 -0400
Processing by Devise::SessionsController#new as HTML
  Rendered devise/shared/_links.erb (1.0ms)
  Rendered devise/sessions/new.html.erb within layouts/application (5.3ms)
Completed 200 OK in 20ms (Views: 18.9ms)

patch on user.rb

  class << self
    def serialize_from_session(key,salt)
      #record = to_adapter.get(key[0].to_param)                                                                                                                                 
      record = to_adapter.get(key.to_s)
      record if record && record.authenticatable_salt == salt
    end
  end
@victorsosa
Copy link
Author

Also I found out that: if user_signed_in? is not working properly neither

@victorsosa
Copy link
Author

Nevermind I found the answer in: #2949

you can close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant