mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
fix: update 2FA support descriptions and improve error handling in TOTP actions
This commit is contained in:
+4
-2
@@ -611,14 +611,16 @@ export default function App() {
|
||||
|
||||
async function enableTotpAction(secret: string, token: string) {
|
||||
if (!secret.trim() || !token.trim()) {
|
||||
pushToast('error', t('txt_secret_and_code_are_required'));
|
||||
return;
|
||||
const error = new Error(t('txt_secret_and_code_are_required'));
|
||||
pushToast('error', error.message);
|
||||
throw error;
|
||||
}
|
||||
try {
|
||||
await setTotp(authedFetch, { enabled: true, secret: secret.trim(), token: token.trim() });
|
||||
pushToast('success', t('txt_totp_enabled'));
|
||||
} catch (error) {
|
||||
pushToast('error', error instanceof Error ? error.message : t('txt_enable_totp_failed'));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +55,14 @@ export default function SettingsPage(props: SettingsPageProps) {
|
||||
}, [props.profile.email, secret]);
|
||||
|
||||
async function enableTotp(): Promise<void> {
|
||||
await props.onEnableTotp(secret, token);
|
||||
// Secret is now stored on the server; remove plaintext copy from localStorage.
|
||||
localStorage.removeItem(totpSecretStorageKey);
|
||||
setTotpLocked(true);
|
||||
try {
|
||||
await props.onEnableTotp(secret, token);
|
||||
// Secret is now stored on the server; remove plaintext copy from localStorage.
|
||||
localStorage.removeItem(totpSecretStorageKey);
|
||||
setTotpLocked(true);
|
||||
} catch {
|
||||
// Keep inputs editable after a failed attempt.
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRecoveryCode(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user