I currently have an app that uses regular Devise authentication for logging in and out, but uses Devise's token_authenticatable module to create a unique token that is used when submitting data to the app from a bookmarklet. Each user gets a unique bookmarklet with their authenticity token baked right into the javascript. However, the way Devise is currently set up, the user has no auth token by default. They have to go to the /edit/users page, press "Generate Token" and then they have one in the db.
I need a way to tell Devise to automatically generate an auth token for each user at sign up.
I'm a newbie, and I'm not sure where to find the Devise controllers to edit this, and even if I could find them, I'm not entirely sure what I would do. Any help is welcome! Thanks.
You can use the helper ensure_authentication_token
of Devise::Models::TokenAuthenticatable
module.
So you User
class might be like this:
class User < ActiveRecord::Base
devise :database_authenticatable
before_save :ensure_authentication_token
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With