-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
User tokens don't properly deserialize #121
Comments
I ended up overriding destroy_expired_tokens in my user model: def destroy_expired_tokens
return if self.tokens == '{}'
super
end |
@sdornan - thanks for the detailed error report. I'll look into this ASAP |
+1 |
👍, why not make the |
@shicholas - there's no guarantee that |
Sure sounds good. Please give me a few days. |
Sounds good. Thanks! |
#276 I have some questions about testing I'll pose there. |
Closing as we now support |
Just in case anyone else stumbles upon this issue, instead of overriding destroy_expired_tokens you can simply set user tokens to nil during the initial migration. The User model will then call the set_empty_token_hash callback defined in the provided model concern. This was run on rails 4.2.4, devise_token_auth 0.1.34, mysql server 5.5.40. Here's my modified migration: class AddDeviseTokenAuthFieldsToUsers < ActiveRecord::Migration
def change
add_column :users, :provider, :string, null: false, default: "email"
add_column :users, :uid, :string, null: false, default: ""
add_column :users, :tokens, :text
reversible do |direction|
direction.up do
User.find_each do |user|
user.uid = user.email
user.tokens = nil
user.save!
end
end
end
add_index :users, [:uid, :provider], unique: true
end
end |
help to me! I'm use Postgresql and I have go to my row on db for setting to nil, e.j.
Also I've changed my seed file, here it is. I've attempt put your solution on my migration file but not working for me. Here my file "db/migrate/20170321204000_devise_token_auth_create_users.rb". `class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.0]
end |
I dont believe that simply having a User.where(email: '[email protected]').first_or_create do |user|
some_attr = some_val
tokens = nil # or an actual tokens val, any JSON object, any Hash, or any JSON-like String
end The above will always result in some kind of String value that throws the error in the OP on login. I also tried overriding Any form of one-line or block-based What does work for me, is to first create the User record, then reload it, set seeded_user = User.create(email: ...)
seeded_user.reload
seeded_user.tokens = nil
seeded_user.save This actually sets |
Great. It's work for me!!! Thanks |
Still happening as some folks and I see it, I'll make a PR with the fix suggested here. |
+1 |
Hello. There is #1250 PR that should fix this issue. Would you help testing it on your projects? |
This was fixed in #1250, post here if it's still happening when you have this gem from the master branch |
Note that I saw this this evening on a Heroku "pipelines:promotion" where a stage "slug" is moved to prod, after introducing device token auth on an admin user type. Eventually a "restart all dynos" in Heroku solved the problem. Looks like the db:migrate to add the tokens column etc needed a restart to fully bed in. Just an FYI, might save someone a few hours of digging around. |
I am having trouble integrating devise_token_auth v0.1.31.beta9 into an existing Rails 4.2 app that already uses Devise.
I first ran the install. The user model was missing a few columns that devise_token_auth uses, so I edited down the generated migration to:
Attempting to perform the migration results in the following:
It seems that for some reason Rails isn't deserializing the tokens JSON column into a Ruby hash. DeviseTokenAuth::Concerns::User is included in my user modal as it should be. It if makes a difference, I am running Postgres 9.4 as my database.
Any idea what could be causing this?
The text was updated successfully, but these errors were encountered: