mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 17:08:33 +08:00
fix(profile): stop passkey load error toast when feature is disabled
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 commit is contained in:
@@ -205,12 +205,18 @@ function extractErrorMessage(error: unknown, fallback: string): string {
|
||||
}
|
||||
|
||||
async function loadCredentials(): Promise<void> {
|
||||
if (!props.enabled) {
|
||||
credentials.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
credentials.value = await passkeyAPI.list()
|
||||
} catch (error) {
|
||||
const code = (error as { code?: string }).code
|
||||
if (code !== 'PASSKEY_DISABLED') {
|
||||
// 字符串错误码在 reason 字段(code 是数字状态码);
|
||||
// 设置变更竞态下后端仍可能返回 PASSKEY_DISABLED,静默处理
|
||||
const reason = (error as { reason?: string }).reason
|
||||
if (reason !== 'PASSKEY_DISABLED') {
|
||||
appStore.showError(t('profile.passkey.loadFailed'))
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user