# Email change despite not confirming it

**URL:** <https://meta.discourse.org/t/email-change-despite-not-confirming-it/69891>\
**Category:** Bug\
**Created:** [2017 年 9 月 12 日午後 12:42 UTC](https://meta.discourse.org/t/email-change-despite-not-confirming-it/69891 "2017-09-12T12:42:39Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)\
**Post date:** [2017 年 9 月 12 日午後 12:42 UTC](https://meta.discourse.org/t/email-change-despite-not-confirming-it/69891/1 "2017-09-12T12:42:40Z")

</div>

We’ve found a bit of a bizarre bug in our authentication provider, which seems to affect (at least one) core authentication provider, and I expect more.

> **Here's the crux of the problem:**
>
> 1. Create a new account
> 2. Change the email address on that account
> 3. Don’t click on the link in the email
> 4. Log out, log in with the old email
> 5. Observe the email address on that account is now the new email, despite you having not verified it

[https://global.discourse-cdn.com/meta/original/3X/3/9/3918dcfc6bd566e563b442c1e13c9aa3667f0fb5.mp4](https://global.discourse-cdn.com/meta/original/3X/3/9/3918dcfc6bd566e563b442c1e13c9aa3667f0fb5.mp4)

This change of email address despite the user not confirming it will then result in additional bugs depending on the authentication provider in question:

With the one we use in Mozilla, after the steps shown in the video above, a user will no longer be able to log in with their old email, and will have to start logging in with their new one.

With Google, the user will still be able to log in with their old email (because a `GoogleUserInfo` row still exists for it) and will never be able to log in with their new one because a duplicate `user_id` error will be thrown for the new `GoogleUserInfo` row that Discourse tries to create.

That problem can be [seen in a spec I wrote, which passes when it _ **really shouldn’t** _](https://github.com/LeoMcA/discourse/commit/a48bd121af1dc480691f581071de8e922ad966c6#diff-56d0337c547fbfea101cd1a1d250b6ccR196):

```ruby
updater = EmailUpdater.new(user.guardian, user)
updater.change_to(new_email)

user.reload
expect(user.email).to eq(old_email)

response = login(old_identity)
expect(response['authenticated']).to eq(true)

user.reload
expect(user.email).to eq(new_email)

expect { login(new_identity) }.to raise_error(ActiveRecord::RecordNotUnique)

```

I’m starting to attempt to find a fix, but I thought I’d post now that I’ve finally nailed down the actual bug, in case anyone else had any ideas.

---

_[View the full topic](https://meta.discourse.org/t/email-change-despite-not-confirming-it/69891)._
