devise_token_auth icon indicating copy to clipboard operation
devise_token_auth copied to clipboard

Devise token auth tries to send confirmation email even though it is disabled

Open uriklar opened this issue 10 years ago • 13 comments

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

uriklar avatar May 22 '15 17:05 uriklar

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

uriklar avatar May 22 '15 17:05 uriklar

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! }

uriklar avatar May 22 '15 17:05 uriklar

+1 @uriklar thanks

shoobm avatar May 23 '15 06:05 shoobm

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

dekz avatar May 26 '15 08:05 dekz

Same problem here. Seems that devise configuration in DeviseTokenAuth::Concerns::User overrides configuration in the local model User.

micred avatar Jun 17 '16 15:06 micred

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?

adis-io avatar Jun 25 '16 11:06 adis-io

@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

JackWCollins avatar Jul 20 '16 14:07 JackWCollins

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

JackWCollins avatar Jul 20 '16 23:07 JackWCollins

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 avatar Oct 13 '16 09:10 felixyz

@felixyz But that doesn't solve it if you need the confirmation for the web app and not the api.

taiwoayanleye avatar Jun 17 '17 16:06 taiwoayanleye

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?

gmverdon avatar May 12 '18 20:05 gmverdon

Add this to your routes.rb file default_url_options :host => "example.com" will solve this error @uriklar

AmanRelan avatar Mar 28 '19 07:03 AmanRelan

Moving include DeviseTokenAuth::Concerns::User before devise :confirmable solved the issue for me.

tannakartikey avatar Apr 23 '22 08:04 tannakartikey