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

devise + mongoid #2949

Closed
eddiefisher opened this issue Mar 27, 2014 · 51 comments
Closed

devise + mongoid #2949

eddiefisher opened this issue Mar 27, 2014 · 51 comments

Comments

@eddiefisher
Copy link

application successful working with mongoid, after install devise I try to login in application but got error

The operation: #<Moped::Protocol::Query @Length=124 @request_id=2 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="ereader_development.users" @Skip=0 @limit=-1 @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('5333276a6d6163c871000000')}}, "$orderby"=>{:_id=>1}} @fields=nil> failed with error 10068: "invalid operator: $oid" See https://github.com/mongodb/mongo/blob/master/docs/errors.md for details about this error.

@josevalim
Copy link
Contributor

You need to give us more information on how to reproduce this issue, otherwise there is nothing we can do. Please read CONTRIBUTING.md file for more information about creating bug reports. Thanks!

@josevalim
Copy link
Contributor

Actually, this is the same issue as: #2882

We don't have Devise working on the latest mongo yet.

@Fudoshiki
Copy link
Contributor

when i entered email and password:

Moped::Errors::QueryFailure in Admin::ProjectsController#index

The operation: #<Moped::Protocol::Query @Length=124 @request_id=4 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="mystand_development.users" @Skip=0 @limit=-1 @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534513085533310d78000000')}}, "$orderby"=>{:_id=>1}} @fields=nil> failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid" See https://github.com/mongodb/mongo/blob/master/docs/errors.md for details about this error.

{"utf8"=>"✓",
"authenticity_token"=>"v6Fr0h9rCggpg5Qe1cLSJh/RRz73hrUQk5r93U+Xtdc=",
"user"=>{"email"=>"admin",
"password"=>"[FILTERED]",
"remember_me"=>"0"},
"commit"=>"Sign in",
"locale"=>"ru"}

@felipero
Copy link

Assuming that this issue happens on rails 4.1.0, that's probably an issue with the cookies serializer. Remove the line below from the cookies_serializer.rb as a workaround.

Rails.application.config.action_dispatch.cookies_serializer = :json

I'm not sure it is an issue with devise or rails 4.1 or mongoid.

@santa-1987
Copy link

I too get the Same error while trying to fetch current_user in ruby 2.1.1 and rails 4.1.0

[2] pry(#<#<Class:0x0000000662bbe0>>)> current_user
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e21e57573651144000000')}}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 1.3477ms
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query
  @length=124
  @request_id=4
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="htmlgen_development.users"
  @skip=0
  @limit=-1
  @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e21e57573651144000000')}}, "$orderby"=>{:_id=>1}}
  @fields=nil>
failed with error 10068: "invalid operator: $oid"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
from /home/usermac44/.rvm/gems/ruby-2.1.1@htmlgen/gems/moped-2.0.0.rc1/lib/moped/operation/read.rb:50:in `block in execute'

I use Gems:

gem 'devise', github: 'plataformatec/devise'
gem 'mongoid', github: 'mongoid/mongoid'
gem 'bson_ext'

Tried with all of the versions available for devise including lm-rails-4
Let us Know the Solution for this.

Thanks in advance !!!

@eddiefisher
Copy link
Author

I'm just removed mongoid and install postgreSQL =)

@santosh-1987
Copy link

I tried to Debug to some extent , but yet to land in a full proof solution:

In User Model Added:

class << self
    def serialize_from_session(key, salt)
      binding.pry
      record = to_adapter.get(key.to_s)
      record if record && record.authenticatable_salt == salt
    end
  end

Have a Look at debugging logs -

From: /home/usermac44/workspace/htmlgen/app/models/user.rb @ line 39 User.serialize_from_session:

    38: def serialize_from_session(key, salt)
 => 39:   binding.pry
    40:   record = to_adapter.get(key.to_s)
    41:   record if record && record.authenticatable_salt == salt
    42: end

[1] pry(User)> key
=> [{"$oid"=>"534e514975736527d5000000"}]
[2] pry(User)> salt
=> "$2a$10$wagRGskPgMrtKfui7t04Oe"
[3] pry(User)> to_adapter.get(key.to_s)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>"[{\"$oid\"=>\"534e514975736527d5000000\"}]"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.5147ms
=> nil
[4] pry(User)> to_adapter.get(key)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 1.2428ms
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query
  @length=124
  @request_id=25
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="htmlgen_development.users"
  @skip=0
  @limit=-1
  @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}}
  @fields=nil>
failed with error 10068: "invalid operator: $oid"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
from /home/usermac44/.rvm/gems/ruby-2.1.1@htmlgen/gems/moped-2.0.0.rc1/lib/moped/operation/read.rb:50:in `block in execute'
[5] pry(User)> to_adapter.get(key.to_s)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>"[{\"$oid\"=>\"534e514975736527d5000000\"}]"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4418ms
=> nil
[6] pry(User)> User.all.last
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{}, "$orderby"=>{:_id=>-1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 7.3730ms
=> #<User _id: 534e514975736527d5000000, email: "xyz@gmail.com", encrypted_password: "$2a$10$wagRGskPgMrtKfui7t04OeIkxHbWeWYmEsJfifVHHZsVjyRs/PMqm", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: 2014-04-16 09:51:50 UTC, last_sign_in_at: 2014-04-16 09:45:56 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1">
[7] pry(User)> key.to_s
=> "[{\"$oid\"=>\"534e514975736527d5000000\"}]"
[8] pry(User)> to_adapter
=> #<Mongoid::Document::OrmAdapter:0x00000005be83e0 @klass=User>
[9] pry(User)> to_adapter.get
ArgumentError: wrong number of arguments (0 for 1)
from /home/usermac44/.rvm/gems/ruby-2.1.1@htmlgen/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/mongoid.rb:21:in `get'
[10] pry(User)> to_adapter.get("asdfasd")
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>"asdfasd"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4259ms
=> nil
[11] pry(User)> to_adapter.get("534e514975736527d5000000")
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('534e514975736527d5000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.6219ms
=> #<User _id: 534e514975736527d5000000, email: "xyz@gmail.com", encrypted_password: "$2a$10$wagRGskPgMrtKfui7t04OeIkxHbWeWYmEsJfifVHHZsVjyRs/PMqm", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: 2014-04-16 09:51:50 UTC, last_sign_in_at: 2014-04-16 09:45:56 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1">
[12] pry(User)> key
=> [{"$oid"=>"534e514975736527d5000000"}]
[13] pry(User)> to_adapter.get(key)
  MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=>1} runtime: 0.5481ms
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 1.0496ms
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query
  @length=124
  @request_id=31
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="htmlgen_development.users"
  @skip=0
  @limit=-1
  @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}}
  @fields=nil>
failed with error 10068: "invalid operator: $oid"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
from /home/usermac44/.rvm/gems/ruby-2.1.1@htmlgen/gems/moped-2.0.0.rc1/lib/moped/operation/read.rb:50:in `block in execute'
[14] pry(User)> to_adapter.get(key.to_json)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>"[{\"$oid\":\"534e514975736527d5000000\"}]"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4362ms
=> nil
[15] pry(User)> to_adapter.get(key.to_s)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>"[{\"$oid\"=>\"534e514975736527d5000000\"}]"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4271ms
=> nil
[16] pry(User)> to_adapter.get(key)
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 1.1631ms
Moped::Errors::QueryFailure: The operation: #<Moped::Protocol::Query
  @length=124
  @request_id=34
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="htmlgen_development.users"
  @skip=0
  @limit=-1
  @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('534e514975736527d5000000')}}, "$orderby"=>{:_id=>1}}
  @fields=nil>
failed with error 10068: "invalid operator: $oid"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.
from /home/usermac44/.rvm/gems/ruby-2.1.1@htmlgen/gems/moped-2.0.0.rc1/lib/moped/operation/read.rb:50:in `block in execute'
[17] pry(User)> to_adapter.get("534e514975736527d5000000")
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('534e514975736527d5000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.6438ms
=> #<User _id: 534e514975736527d5000000, email: "xyz@gmail.com", encrypted_password: "$2a$10$wagRGskPgMrtKfui7t04OeIkxHbWeWYmEsJfifVHHZsVjyRs/PMqm", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: 2014-04-16 09:51:50 UTC, last_sign_in_at: 2014-04-16 09:45:56 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1">
[18] pry(User)> record = to_adapter.get("534e514975736527d5000000")
  MOPED: 127.0.0.1:27017 QUERY        database=htmlgen_development collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('534e514975736527d5000000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.5525ms
=> #<User _id: 534e514975736527d5000000, email: "xyz@gmail.com", encrypted_password: "$2a$10$wagRGskPgMrtKfui7t04OeIkxHbWeWYmEsJfifVHHZsVjyRs/PMqm", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 3, current_sign_in_at: 2014-04-16 09:51:50 UTC, last_sign_in_at: 2014-04-16 09:45:56 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1">
[19] pry(User)> record && record.authenticatable_salt == salt
=> true

@gurix
Copy link

gurix commented May 7, 2014

Thanks @felipero I ran in the same problem, you saved my day.

@djsmentya
Copy link

add to your Devise model this
Rails 4.1.0

#app/models/user.rb
class << self
  def serialize_from_session(key, salt)
    record = to_adapter.get(key[0]["$oid"])
    record if record && record.authenticatable_salt == salt
  end
end

Error happens because the warden session is not right
it is for current rails 4.1.0 with mongoid

session["warden.user.user.key"] #=> [[{"$oid"=>"53690f8b646a7342bd000000"}], "$2a$10$LswY1XOoAOgTLCO0.Lc7m."] 

it is for rails 3.2.13 with active record

session["warden.user.user.key"] #=> [[1], "$2a$10$KFxDEv1771Jd9kGeJRuHNe"]

warden session store not id, it is store a hash
who know where warden session initialize?

@btrepp
Copy link

btrepp commented May 11, 2014

Using rememberable i've also had to do this for serialize_from_cookie

It might be good to add some error checking to devise in regards to this. If a cookie has invalid data it should just fail to authenticate, rather than throw a runtime exception on the server.

@AdrienGiboire
Copy link

I don't use Devise and I met the same issue so I'd say it's not related to Devise.

@adrianpacala
Copy link
Contributor

This is related to how bson-ruby serializes BSON::ObjectId objects now. If you want to move back to the old format, create config/initializers/bson.rb and add this:

module BSON
  class ObjectId
    def as_json(*args)
      to_s
    end
  end
end

@junhao
Copy link

junhao commented Jun 15, 2014

I got the same error. My issue seems to be with the compatibility of rails 4.1.0 and mongoid 4.0.0.rc1. Everything works fine after I downgraded rails to 4.0.5.
https://github.com/mongoid/mongoid/issues/3626

@mpgarate
Copy link

Thanks @adrpac. Your suggestion to override the BSON module worked for me on rails 4.1.1.

@fransstudio2
Copy link

Hello, I created a new application with rails 4.1.1 and mongoid 4.0.0. I tried the solution from @adrpac, but it doesnt work. Can you help me? I tried putting debugger in everything, but it wont be called at all.

Thanks!

@ArthurCamara
Copy link

@fransstudio2 Fran, I had the same issue as you, and this is how I solved it:
add the following inside the user class (or any other class that you are using devise with):

class << self
  def serialize_from_session(key,salt)
    record = to_adapter.get(key[0].to_param)
    record if record && record.authenticatable_salt == salt
  end
end

@fransstudio2
Copy link

Thanks! I solved it with modification. I put this inside user.rb. class User. Somehow i need to overwrite serialize_into_session instead of from session. I'm still figuring things out, so it might be wrong.

#HACK FOR DEVISE 3.2.4
def self.serialize_into_session(record)
    [record.id.to_s, record.authenticatable_salt]
end

@ThePhen
Copy link

ThePhen commented Jul 2, 2014

Thanks @adrpac, your suggestion got me up & running.

@ghost
Copy link

ghost commented Jul 3, 2014

Thanks @fransstudio2 your hack works!.

Mongoid 4.0.0 - Rails 4.1.4 - Devise 3.2.4

@jengel3
Copy link

jengel3 commented Jul 9, 2014

Running MongoId 4.0.0, Rails 4.1.4, and devise 3.2.4, and none of these solutions are working for me. I'm getting the same error every time. Any help?

@kathgironpe
Copy link

@Jake0oo0 This works for me:

def self.serialize_into_session(record)
    [record.id.to_s, record.authenticatable_salt]
end

I use the same versions.

@kittrCZ
Copy link

kittrCZ commented Jul 10, 2014

Thanks @djsmentya this worked for me!

rails (4.1.4), devise (3.2.4), mongoid (4.0.0), moped (2.0.0), bson (2.3.0)

@vassilis
Copy link

Comment out the line below from the cookies_serializer.rb

Rails.application.config.action_dispatch.cookies_serializer = :json

Delete cookies.
Restart server.

rails 4.1.4, devise 3.2.4, mongoid 4.0.0

@jengel3
Copy link

jengel3 commented Jul 18, 2014

@vassilis I tried this, but I still couldn't get it to work. It may have been an issue with converting to MongoID in an ongoing project. Anyway, I was able to revert to rails 4.0.4, and it worked fine.

@klebershimabuku
Copy link

Same as @vassilis.

+1 for comment out the cookies_serializer.rb line.

@victorsosa
Copy link

+1 for comment out the cookies_serializer.rb line.

@shyammohankanojia
Copy link

+1 for comment out the cookies_serializer.rb line.

@rjurado01
Copy link

This works for me (Rails 4.1.6, Mongoid 4.0.0, Devise 3.3.0):

#app/models/user.rb
class User
  include Mongoid::Document
  ...
  def self.serialize_from_session(key, salt)
    record = to_adapter.get(key[0]["$oid"])
    record if record && record.authenticatable_salt == salt
  end
end

Thanks @djsmentya.

@VFedyk
Copy link

VFedyk commented Oct 9, 2014

@rjurado01 thanks. It worked for me.

Rails 4.1.6, Mongoid 4.0.0, Devise 3.4.0

odarriba added a commit to odarriba/watchr that referenced this issue Oct 11, 2014
ADD: More complex SMTP configuration
Allowing to set if the connection with the SMTP server is using
a plain, SSL/TLS or STARTTLS security mode.

MODIFY: Comments in default configuration file
Added more detailed comments to provide the available values
in every configuration flag.

FIX: Bug with Devise and Rails 4.1
There is a bug in session cookie encoding that causes a fail
retrieving the user session from MongoDB.
It was  solved using the indications readed here:
heartcombo/devise#2949 (comment)
@leetheguy
Copy link

I found this while searching for a similar problem with sorcery instead of devise.
@adrpac's solution worked for me.

@danijel
Copy link

danijel commented Oct 31, 2014

@rjurado01 thanks, this works for me on Rails 4.1.7, Mongoid 4.0.0, Devise 3.4.1

@tirdadc
Copy link

tirdadc commented Nov 2, 2014

Tedious that this is still an issue with Rails 4.1.7, Mongoid 4.0.0 and Devise 3.4.0.

@kalelc
Copy link

kalelc commented Nov 4, 2014

@rjurado01 Thanks, works in 4.1.6, MongoId 4.0.0 and Devise 3.4.0

gato-omega pushed a commit to gato-omega/sample_app_thesis_manager that referenced this issue Nov 5, 2014
@leckylao
Copy link

leckylao commented Nov 6, 2014

Tried all these 3 ways and all works well with Rails 4.2, Mongoid 4.0.0, Devise 3.0.2 thanks @felipero @adrpac @fransstudio2 . And I personally like the comment out Rails 4 cookies_serializer which is easier.

@murtza
Copy link

murtza commented Nov 11, 2014

@rjurado01 Thanks, your code works in 4.2.0.beta4, Mongoid 4.0.0 and Devise 3.4.1

@JohnViviano
Copy link

Thanks everyone.

I'm using Rails 4.1.7, Mongoid 4.0.0, and Devise 3.4.1.
I only encountered this problem with Devise :rememberable, and Firefox -- I haven't seen the problem with any other browsers.

I followed the advise from @btrepp. It's working for me.

class User
include Mongoid::Document
...

class << self
def serialize_from_cookie(id, remember_token)
#debugger
record = to_adapter.get(id.to_s)
record if record && !record.remember_expired? &&
Devise.secure_compare(record.rememberable_value, remember_token)
end
end
...

@iduuck
Copy link

iduuck commented Nov 19, 2014

Doesn't work for me with Rails 4.1.4, Mongoid 4.0.0 and Devise 3.4.1...

Always getting this error:

The operation: #<Moped::Protocol::Query
  @length=127
  @request_id=38
  @response_to=0
  @op_code=2004
  @flags=[]
  @full_collection_name="sketchnews_development.users"
  @skip=0
  @limit=-1
  @selector={"$query"=>{"_id"=>{"$oid"=>BSON::ObjectId('546cb9c84e69631b95000000')}}, "$orderby"=>{:_id=>1}}
  @fields=nil>
failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.

@iduuck
Copy link

iduuck commented Nov 19, 2014

When commenting out the cookies_serializer line I get the following error:

incompatible marshal file format (can't be read)
    format version 4.8 required; 123.34 given

@JohnViviano
Copy link

@iduuck - In my case the error was being thrown from either serialize_from_cookies or serialize_from_session. I use the better_errors gem which helped me identify where the failure was coming from. If you find that the errors originate in either of those two methods, then you should be able to override them as shown above. Good luck!

@iduuck
Copy link

iduuck commented Nov 19, 2014

@JohnViviano It now works, but if I want to sign in, I am just being redirected to / and user_signed_in? is yet empty (so is current_user)

@hoang1417
Copy link

@djsmentya's solution worked for me with Rails 4.1.5, Mongoid 4.0.0 and Devise 3.4
Many thanks!

@mahtab732
Copy link

Thanks @adrpac. Bson code working.Thank you

ndd314 added a commit to ndd314/gridfs_manager that referenced this issue Dec 5, 2014
@dimidev
Copy link

dimidev commented Jan 1, 2015

@rjurado01 thx it works for me too

@rdetert
Copy link

rdetert commented Jan 11, 2015

I'm using Rails 4.1.8. I got it working by:

  1. Commenting out Rails.application.config.action_dispatch.cookies_serializer = :json as others have mentioned
  2. Deleting cookies and restarting server
  3. Added random string to the key in the session_store.rb

@andreicristianpetcu
Copy link

thank you @ArthurCamara and @fransstudio2 Your solutions worked for me. I needed to delete the old cookies and then it worked.

@pencilcheck
Copy link

@adrpac thanks that works

@ghost
Copy link

ghost commented Feb 9, 2015

Thanks @rjurado01. That works for me with rails 4.1.6, devise 3.4.1 and mongoid 4.0.1. However I have to modify your method adding "as_json" because I always obtain an error when try to access to "$oid":

...
def self.serialize_from_session(key, salt)
  record = to_adapter.get(key[0].as_json["$oid"])
  record if record && record.authenticatable_salt == salt
end
...

zmilojko added a commit to zmilojko/tk15 that referenced this issue Feb 13, 2015
This is somewhat explained here:

heartcombo/devise#2949

but it is because how mongoid creates that $oid and devise doesn't
like it.

Signed-off-by: zeljko <zeljko@zwr.fi>
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