From 6e66ba202f892d236f99e5013ff33ae39ae19919 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Sun, 19 Nov 2023 04:32:25 -0800 Subject: [PATCH] Add a button to delete all refresh tokens (#18680) Co-authored-by: Bram Kragten --- src/panels/profile/ha-refresh-tokens-card.ts | 31 ++++++++++++++++++++ src/translations/en.json | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/panels/profile/ha-refresh-tokens-card.ts b/src/panels/profile/ha-refresh-tokens-card.ts index 6217936dcb46..3523acc417e2 100644 --- a/src/panels/profile/ha-refresh-tokens-card.ts +++ b/src/panels/profile/ha-refresh-tokens-card.ts @@ -9,6 +9,7 @@ import "../../components/ha-card"; import "../../components/ha-settings-row"; import "../../components/ha-icon-button"; import { RefreshToken } from "../../data/refresh_token"; +import { deleteAllRefreshTokens } from "../../data/auth"; import { showAlertDialog, showConfirmationDialog, @@ -108,6 +109,13 @@ class HaRefreshTokens extends LitElement { ) : ""} +
+ + ${this.hass.localize( + "ui.panel.profile.refresh_tokens.delete_all_tokens" + )} + +
`; } @@ -139,6 +147,29 @@ class HaRefreshTokens extends LitElement { } } + private async _deleteAllTokens(): Promise { + if ( + !(await showConfirmationDialog(this, { + text: this.hass.localize( + "ui.panel.profile.refresh_tokens.confirm_delete_all" + ), + destructive: true, + })) + ) { + return; + } + try { + await deleteAllRefreshTokens(this.hass); + } catch (err: any) { + await showAlertDialog(this, { + title: this.hass.localize( + "ui.panel.profile.refresh_tokens.delete_failed" + ), + text: err.message, + }); + } + } + static get styles(): CSSResultGroup { return [ haStyle, diff --git a/src/translations/en.json b/src/translations/en.json index 0a0606abf351..aded614d0273 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -5537,6 +5537,8 @@ "last_used": "Last used {date} from {location}", "not_used": "Has never been used", "confirm_delete": "Are you sure you want to delete the refresh token for {name}?", + "delete_all_tokens": "Delete all tokens", + "confirm_delete_all": "Are you sure you want to delete all refresh tokens? You will be logged out as part of this operation.", "delete_failed": "Failed to delete the refresh token.", "current_token_tooltip": "Unable to delete current refresh token" },