mirror of
https://github.com/handsomezhuzhu/2fa-tool.git
synced 2026-04-18 22:32:53 +00:00
fix: add deduplication in token import function
Add logic to filter out duplicate tokens on import. Co-authored-by: Simon <85533298+handsomezhuzhu@users.noreply.github.com>
This commit is contained in:
11
app/page.tsx
11
app/page.tsx
@@ -617,13 +617,20 @@ export default function TwoFactorAuth() {
|
|||||||
|
|
||||||
const imported = JSON.parse(decrypted)
|
const imported = JSON.parse(decrypted)
|
||||||
if (Array.isArray(imported)) {
|
if (Array.isArray(imported)) {
|
||||||
setTokens([...tokens, ...imported])
|
const existingSecrets = new Set(tokens.map((tk) => tk.secret.toUpperCase()))
|
||||||
|
const newTokens = (imported as TOTPToken[]).filter(
|
||||||
|
(tk) => !existingSecrets.has(tk.secret.toUpperCase())
|
||||||
|
)
|
||||||
|
const skipped = imported.length - newTokens.length
|
||||||
|
setTokens((prev) => [...prev, ...newTokens])
|
||||||
setImportPassword("")
|
setImportPassword("")
|
||||||
setImportFile(null)
|
setImportFile(null)
|
||||||
setShowImportPassword(false)
|
setShowImportPassword(false)
|
||||||
toast({
|
toast({
|
||||||
title: t.importSuccess,
|
title: t.importSuccess,
|
||||||
description: `${t.added} ${imported.length} ${t.importedTokens}`,
|
description: skipped > 0
|
||||||
|
? `${t.added} ${newTokens.length} ${t.importedTokens},已跳过 ${skipped} 个重复令牌`
|
||||||
|
: `${t.added} ${newTokens.length} ${t.importedTokens}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user