web: toast passkey registration failures
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/e2e Pipeline was successful

This commit is contained in:
justme committed 2026-10-22 05:59:56 +08:00
1 parent 758b6b1566
commit bf2a598891
1 file changed
+12 -4
+12 -4
View File
@@ -1,7 +1,7 @@
import { Plus } from 'lucide-react'
import { useState } from 'react'
import { passkeySupported, registerPasskey, type PasskeyPlace } from '@shared/api/webauthn'
import { guessPlatform, useAction, useToast } from '@shared/ui'
import { describeError, guessPlatform, useAction, useToast } from '@shared/ui'
/** 默认的 passkey 名称:按浏览器所在的系统给一个能认出来的名字。 */
function defaultName(): string {
@@ -38,10 +38,18 @@ export function PasskeyAddForm({ onAdded, compact }: { onAdded: () => void; comp
try {
added = (await registerPasskey(name.trim(), place)).name
} catch (e) {
if (e instanceof DOMException && e.name === 'NotAllowedError') throw new Error('已取消')
throw e
if (e instanceof DOMException && e.name === 'NotAllowedError') {
toast('在浏览器的提示里取消了,或者超时了。可以重新点「添加 Passkey」再试一次。', true, { title: 'Passkey 没有添加', ms: 10_000 })
} else {
// 失败也像成功一样弹出来、停 10 秒:写清楚原因和常见的排查方向,点一下可以提前关掉
toast(`${describeError(e)}。常见原因:页面地址(来源)和面板配置的 WebAuthn 来源不一致、所选保存位置不被浏览器支持、没有通过 HTTPS 或 localhost 打开。`, true, { title: 'Passkey 添加失败', ms: 10_000 })
}
})
return false
}
return true
}).then((done) => done && added !== undefined)
if (ok) {
// 成功提示停 10 秒:说清楚存了什么、下一步怎么用,点一下可以提前关掉
toast(`「${added}」已经保存。下次登录时点用户名框选它,或者点「使用 Passkey 登录」;建议再添加一个备用的。`, false, { title: 'Passkey 添加成功', ms: 10_000 })