fix(api): UserDetail 读不到绑定账号时返回错误,不再显示为未绑定

This commit is contained in:
Lemon-miaow committed 2026-09-27 13:18:37 +08:00
1 parent 01408014b2
commit fef8d962c9
2 files changed
+66 -3

No files matched your search

+8 -3
View File
@@ -2000,18 +2000,23 @@ func (p *PGRepo) UserDetail(ctx context.Context, userID string) (*UserDetail, er
linkRows, err := p.db.QueryContext(ctx,
`SELECT mc_uuid::text, COALESCE(auth_source, 'mojang'), verified_at
FROM account_links WHERE user_id = $1 ORDER BY verified_at`, userID)
// A failed read is the call's failure: an empty list would tell the admin the
// user has no Minecraft account linked.
if err != nil {
return &d, nil // best-effort; linked accounts are informational
return nil, err
}
defer linkRows.Close()
for linkRows.Next() {
var a LinkedAccount
if err := linkRows.Scan(&a.MCUUID, &a.AuthSource, &a.VerifiedAt); err != nil {
return &d, nil
return nil, err
}
d.LinkedAccounts = append(d.LinkedAccounts, a)
}
return &d, linkRows.Err()
if err := linkRows.Err(); err != nil {
return nil, err
}
return &d, nil
}
// CreateUser mints a new user row. A username conflict → ErrConflict.