-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Comments
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! |
Actually, this is the same issue as: #2882 We don't have Devise working on the latest mongo yet. |
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"=>"✓", |
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. |
I too get the Same error while trying to fetch current_user in ruby 2.1.1 and rails 4.1.0
I use Gems: gem 'devise', github: 'plataformatec/devise' Tried with all of the versions available for devise including lm-rails-4 Thanks in advance !!! |
I'm just removed mongoid and install postgreSQL =) |
I tried to Debug to some extent , but yet to land in a full proof solution: In User Model Added:
Have a Look at debugging logs -
|
Thanks @felipero I ran in the same problem, you saved my day. |
add to your Devise model this #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 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 |
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. |
I don't use Devise and I met the same issue so I'd say it's not related to Devise. |
This is related to how bson-ruby serializes BSON::ObjectId objects now. If you want to move back to the old format, create module BSON
class ObjectId
def as_json(*args)
to_s
end
end
end |
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. |
Thanks @adrpac. Your suggestion to override the BSON module worked for me on rails 4.1.1. |
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! |
@fransstudio2 Fran, I had the same issue as you, and this is how I solved it: 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 |
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 |
Thanks @adrpac, your suggestion got me up & running. |
Thanks @fransstudio2 your hack works!. Mongoid 4.0.0 - Rails 4.1.4 - Devise 3.2.4 |
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? |
@Jake0oo0 This works for me:
I use the same versions. |
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) |
Comment out the line below from the cookies_serializer.rb
Delete cookies. rails 4.1.4, devise 3.2.4, mongoid 4.0.0 |
@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. |
Same as @vassilis. +1 for comment out the cookies_serializer.rb line. |
+1 for comment out the cookies_serializer.rb line. |
+1 for comment out the cookies_serializer.rb line. |
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. |
@rjurado01 thanks. It worked for me. Rails 4.1.6, Mongoid 4.0.0, Devise 3.4.0 |
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)
I found this while searching for a similar problem with sorcery instead of devise. |
@rjurado01 thanks, this works for me on Rails 4.1.7, Mongoid 4.0.0, Devise 3.4.1 |
Tedious that this is still an issue with Rails 4.1.7, Mongoid 4.0.0 and Devise 3.4.0. |
@rjurado01 Thanks, works in 4.1.6, MongoId 4.0.0 and Devise 3.4.0 |
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. |
@rjurado01 Thanks, your code works in 4.2.0.beta4, Mongoid 4.0.0 and Devise 3.4.1 |
Thanks everyone. I'm using Rails 4.1.7, Mongoid 4.0.0, and Devise 3.4.1. I followed the advise from @btrepp. It's working for me. class User class << self |
Doesn't work for me with Rails 4.1.4, Mongoid 4.0.0 and Devise 3.4.1... Always getting this error:
|
When commenting out the cookies_serializer line I get the following error:
|
@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! |
@JohnViviano It now works, but if I want to sign in, I am just being redirected to |
@djsmentya's solution worked for me with Rails 4.1.5, Mongoid 4.0.0 and Devise 3.4 |
Thanks @adrpac. Bson code working.Thank you |
@rjurado01 thx it works for me too |
I'm using Rails 4.1.8. I got it working by:
|
thank you @ArthurCamara and @fransstudio2 Your solutions worked for me. I needed to delete the old cookies and then it worked. |
@adrpac thanks that works |
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":
|
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>
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.
The text was updated successfully, but these errors were encountered: