fix(profile): 修复未配置 Passkey 时 /profile 每次访问都弹「加载 Passkey 失败」 - #5024
#5024Merged
Wei-Shaw merged 1 commit intoJul 29, 2026
mainWei-Shaw/sub2api:mainfrom
fix/passkey-disabled-toastWei-Shaw/sub2api:fix/passkey-disabled-toastCopy head branch name to clipboard
Merged
fix(profile): 修复未配置 Passkey 时 /profile 每次访问都弹「加载 Passkey 失败」#5024Wei-Shaw merged 1 commit intomainWei-Shaw/sub2api:mainfrom fix/passkey-disabled-toastWei-Shaw/sub2api:fix/passkey-disabled-toastCopy head branch name to clipboard
Wei-Shaw merged 1 commit into
mainWei-Shaw/sub2api:mainfrom
fix/passkey-disabled-toastWei-Shaw/sub2api:fix/passkey-disabled-toastCopy head branch name to clipboard
Conversation
The PASSKEY_DISABLED silence guard compared the string error code against error.code, but the api client puts the numeric envelope code there and the string code in error.reason, so the guard never matched and every /profile visit on deployments without WebAuthn configured showed a spurious "failed to load passkeys" toast. Read error.reason instead, and skip the credentials request entirely when the feature is disabled so the card no longer issues a request that is guaranteed to fail with 403.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
未配置 WebAuthn(Passkey)的部署,每次访问 /profile 都会弹「加载 Passkey 失败」toast。
根因
ProfilePasskeyCard的加载逻辑本来就设计为静默忽略PASSKEY_DISABLED错误,但比对了错误对象的错误字段:后端错误信封是{ code: 403, reason: "PASSKEY_DISABLED", message: ... }—— 字符串错误码在reason,code是数字状态码。组件用error.code !== 'PASSKEY_DISABLED'判断,永远成立,静默逻辑完全失效。此外组件在
enabled=false(公开设置passkey_enabled为 false)时也会发起GET /user/passkeys请求,注定 403,纯属无谓开销。修复
error.reasonenabled=false时直接跳过请求;保留reason判断以覆盖设置变更竞态(前端认为已启用但后端刚关闭)修复后:未配置 Passkey 时卡片只显示「功能未启用」提示,不发请求、不弹错误。
验证
api/client.ts错误拦截器 reject 的结构({ status, code, reason, message })与后端response.ErrorFrom信封字段一一对应