# Task "users:disable\_2fa" does not disable security keys

**URL:** <https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547>\
**Category:** Bug\
**Created:** [February 28, 2023, 7:55pm UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547 "2023-02-28T19:55:10Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

The discussion addresses a bug where the `users:disable_2fa` task fails to disable security keys, leaving users unable to log in. [pfaffman](/t/-/256547/1) identifies that the task currently does not delete `UserSecurityKey` records and suggests adding `UserSecurityKey.where(user_id: user.id).destroy_all` to fix the issue. [sam](/t/-/256547/2) agrees this is a reasonable improvement and requests a Pull Request. [pfaffman](/t/-/256547/3) initially hesitates due to the need for tests, but later confirms in [pfaffman](/t/-/256547/4) that since no specs exist for this rake task, the fix is straightforward. The proposed solution is linked in [pfaffman](/t/-/256547/4) as [PR #20586](https://github.com/discourse/discourse/pull/20586).

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [February 28, 2023, 7:55pm UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547/1 "2023-02-28T19:55:10Z")

</div>

> <https://github.com/discourse/discourse/blob/main/lib/tasks/users.rake#L153-L159>

If the user has security keys, they are not deleted, so the user still can’t log in.

Unless `UserSecondFactor` is broken somehow, which seems unlikely, the security keys also need to be deleted, something like this:

```
UserSecurityKey.where(user_id: user.id).destroy_all

```

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [February 28, 2023, 11:30pm UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547/2 "2023-02-28T23:30:09Z")

</div>

Sure seems like a reasonable improvement to the task, can you send a PR?

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [March 1, 2023, 12:01am UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547/3 "2023-03-01T00:01:53Z")

</div>

If it were just just one line I’d have done it already, but I’ll really need to create a test or two, which is more daunting (and 4 the work!)

But maybe I can be a big boy.

Just one test that creates a 2fa key and then makes sure it gets cleared? And I guess there’s coffee to create a dummy key in the 2fa code somewhere?

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [March 8, 2023, 2:57pm UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547/4 "2023-03-08T14:57:23Z")

</div>

Well, it doesn’t seem that there are any specs for this take task, so it’s just the single line:

[https://github.com/discourse/discourse/pull/20586](https://github.com/discourse/discourse/pull/20586)

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [March 18, 2023, 8:00am UTC](https://meta.discourse.org/t/task-users-disable-2fa-does-not-disable-security-keys/256547/5 "2023-03-18T08:00:27Z")

</div>

Closed on March 18, 2023, 8:00am UTC

This topic was automatically closed after 4 days. New replies are no longer allowed.
