devise_token_auth
devise_token_auth copied to clipboard
Devise token auth tries to send confirmation email even though it is disabled
Hi, I followed the instructions on disabling the :confirmable option. This is my user.rb file:
class User < ActiveRecord::Base
devise :database_authenticatable, :recoverable,
:trackable, :validatable, :registerable,
:omniauthable
include DeviseTokenAuth::Concerns::User
end
And when registering a user I get the error:
ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url']) %></p>
Any idea why? Thanks, Uri
Ok, so after adding this line:
config.action_mailer.default_url_options = { :host => 'localhost' }
I stop getting the error, but it still sends out the email, so I guess the question still stands. Thanks
Adding this line to user.rb solves the issues. Not sure if this is the right way to solve it though...
before_save -> { skip_confirmation! }
+1 @uriklar thanks
I have the same issue, though a little different.
I assumed since I didn't need confirmable I didn't require confirmation_token in my model, but I guess I was wrong.
PG::UndefinedColumn: ERROR: column users.confirmation_token does not exist
class User < ActiveRecord::Base
#devise :database_authenticatable,
# :trackable, :validatable, :registerable
devise :database_authenticatable
before_save -> { skip_confirmation! }
end
Same problem here. Seems that devise configuration in DeviseTokenAuth::Concerns::User overrides configuration in the local model User.
I have another problem. I use devise-token-auth alongside devise. So when user registers from website - it sends confirmation email, but it doesn't send when I add devise-token-auth's concern. Any ideas?
@micred Were you able to get around that? I tried overwriting that file in a monkey-patch and removing :confirmable but that didn't work. I tried adding before_save -> { skip_confirmation! } to the user model and that didn't work either.
I'm on version 0.1.38
I saw that the code of the confirmable module simply sets the confirmed_at time to now, so setting that in my User model worked for me.
I'm on Rails 5, so perhaps that had something to do with why skip_confirmation! didn't do the trick.
class User < ActiveRecord::Base
include DeviseTokenAuth::Concerns::User
def confirmed_at
Time.now.utc
end
end
From the documentation:
Just list the devise modules that you want to include before including the DeviseTokenAuth::Concerns::User model concern.
Sounds like this might be the gotcha for most people here (as it was for me). Don't include the DTA concern at the top of your user class!
@felixyz But that doesn't solve it if you need the confirmation for the web app and not the api.
Including the DTA at the top of my user class did solve the problem for me. Does including the DTA before including the devise modules have any known issues?
Add this to your routes.rb file default_url_options :host => "example.com" will solve this error
@uriklar
Moving include DeviseTokenAuth::Concerns::User before devise :confirmable solved the issue for me.