-
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
Initial confirmation email not being sent #2688
Comments
Hrm, this is weird. The |
Thanks for the ideas José. Basically at the moment it seems that the # app/controllers/devise/registrations_controller.rb
# POST /resource
def create
build_resource(sign_up_params)
byebug # add in debug statement for tracing
if resource.save
byebug # add in debug statement for tracing
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
# [...snip...] Here is the output of the debug (I have a Membership and Person associated with my User model -- hence the noise):
|
Figures as soon as I post I think I found the method which is doing the nulling. Basically if there is a pending email change it will update the unconfirmed email and then set the confirmed email to the previous email value (which in my case was blank as it is a new user): # lib/devise/models/confirmable.rb
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
@reconfirmation_required = true
self.unconfirmed_email = self.email
self.email = self.email_was
generate_confirmation_token
end Here is the debug session where we can see the email being updated to blank:
With all of that said it does seem to me that these two pieces aren't playing nicely together. Either we would need the type of code introduced which I presented in the initial description (check for email or unconfirmed_email) or possibly modify the above code to only swap if there was a previous email value? |
Thanks for the detailed response. We could fix this but the big question is: why is |
Hey José, completely agree. Base on the trace Here is the flow again that shows how # lib/devise/models/confirmable.rb
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
@reconfirmation_required = true
self.unconfirmed_email = self.email # unconfirmed_email being set to correct email value
self.email = self.email_was # email being unset because self.email_was is ""
generate_confirmation_token
end I'm also a little confused because I can't find Later today I'll see if I can test how this flow works after a registration (i.e. for a regular registered user is self.email_was still "") |
I'm getting an error along these lines as well # lib/devise/models/confirmable.rb
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
|
Hey folks, can you provide a way to reproduce this error? Like, a dummy/simple application pushed to github? :) |
https://github.com/dougvk/devisedebug - let me know what you find out. basically sign up, and it will try to send an email (and fail, because |
Did that help?
|
@dougvk hmm, I can't reproduce it with your app. It's actually trying to send email without any exception... |
I'm going to try to go another round with this specific issue this weekend to see if I can reproduce in a clean way (i.e. new project). My initial debug trace clearly shows the issue however if nobody else can reproduce seems like it must be something env specific. For the time being my override to |
Closing this for now as we can't reproduce. If this pops up, please do open up a new issue or ping this one and we will reopen it! Thanks guys! |
I was experiencing the same problem and was only able to resolve it by setting |
I got this problem too and I found the problem... In fact the So to fix this check everywhere in your code if you have an |
I got the problem (adding a default random-but-unique color attribute for charting after create) and confirmed the cause here. Easy enough for me to postpone these additions until after confirm by moving it out of the model to the after_confirmation_path (I already subvert this action to call other set-up tasks before returning the redirect). Might be one for the wiki if its to be left as a gotcha? |
Same here, @lkol's "config.reconfirmable = false" did resolve this, wondering what the implication might be? |
Same issue. Is there anyone who is able resolve it? |
Same issue with three solutions. I discovered it using devise_invitable and when sending a new invite I got the error:
After tracing through devise_invitable and devise, I determined it happened during By itself, this callback isn't an issue even with devise_invitable. As described by others, the problem occurs when another save happens during creation (typically within def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
@reconfirmation_required = true
self.unconfirmed_email = self.email
self.email = self.email_was
self.confirmation_token = nil
generate_confirmation_token
end At this point, def postpone_email_change?
postpone = self.class.reconfirmable && email_changed? && !@bypass_confirmation_postpone && self.email.present?
@bypass_confirmation_postpone = false
postpone
end The following user model code produces the issue. In this example, class User < ActiveRecord::Base
...
after_save :reveal_issue
def reveal_issue
if self.sign_in_count == 0
self.sign_in_count == 1
self.save
end
end You can then verify it in the console. Create user and see that email is present in the Save user: Check user and email is now Check last user stored and email is present: Obviously a trivial example, but I found the issue because I had an The following solutions have been tested only so far that the model instance Solution 1Use class User < ActiveRecord::Base
...
after_save :reveal_issue
def reveal_issue
if self.sign_in_count == 0
self.skip_reconfirmation!
self.sign_in_count == 1
self.save
end
end Solution 2Make the updates after creation only if confirmation has occurred. This only works for class User < ActiveRecord::Base
...
after_save :reveal_issue
def reveal_issue
if self.confirmed? && self.sign_in_count == 0
self.sign_in_count == 1
self.save
end
end Solution 3Force a record reload before making updates. This fulfills the devise assumption concerning the state of the instance though it is another database hit. class User < ActiveRecord::Base
...
after_save :reveal_issue
def reveal_issue
if self.sign_in_count == 0
self.reload
self.sign_in_count == 1
self.save
end
end |
Hi, I have the same issue, that is not resolved by setting |
For now, I have a hugly workaround: class User < ActiveRecord::Base
devise :confirmable
after_create: force_mail_confirmation
def force_mail_confirmation
self.send_confirmation_instructions
end
end Works like a charm... except that I suspect a Any help is more than welcome |
I'm having this issue too. And it's apparently because of DeviseTokenAuth, for me: class User < ActiveRecord::Base
devise :registerable, :confirmable, :database_authenticatable # (minimal set)
include DeviseTokenAuth::Concerns::User
end Removing the DeviseTokenAuth concerns solves this issue, as does placing it above the devise settings. However, I've currently not tested whether the tokens still work... My fixed User class: class User < ActiveRecord::Base
include DeviseTokenAuth::Concerns::User
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
end |
Wow, thanks to @krsyoung, @antho1404, and @benmaher I spent at least two hours debugging this yesterday and wondering why in the world email was empty. Thanks for the |
@cjbrew The default behavior is explicitly disabled by DeviseTokenAuth.
AFAICT, the "additional params" they're referring to is just |
I'm using devise_token_auth along devise I spent 4 hours searching the solution and finally, this solves that issue thanks a lot @cjbrew |
For those who face this problem whilst using Devise Token Auth, this one solved it for me
|
Per the documentation "Confirmation instructions are sent to the user email after creating a record and when manually requested by a new confirmation instruction request.". However, in my deployment I'm currently not receiving the confirmation emails on initial user creation. The manual request for a confirmation is working perfectly.
I am unsure if it is some side effect of a configuration that I have. I am able to resolve the issue by adding the following code change to
send_confirmation_notification?
to consider the unconfirmed_email as the email value is initially blank:I'm running with Devise 3.1.1 and have the following config settings related to confirmations:
Curious if anybody else is seeing this issue or comments / thoughts on the implications of the code change I have made?
Thanks!
The text was updated successfully, but these errors were encountered: