fix(auth): print only a token that belongs to the selected account

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:15:52 +02:00
1 parent 4d6e68ed85
commit 219798732d
3 files changed
+17 -2

No files matched your search

+4 -1
View File
@@ -37,6 +37,9 @@ type target struct {
var errRepositoryRequired = errors.New("repository required: use --repo owner/name")
// errEnvironmentAccount must not reveal which account the GITEA_TOKEN belongs to.
var errEnvironmentAccount = errors.New("GITEA_TOKEN does not belong to the selected account; supply its matching --user or remove the environment token to use stored credentials")
func (a *application) resolve(ctx context.Context, requireRepo bool) (target, error) {
return a.resolveTarget(ctx, requireRepo, true)
}
@@ -185,7 +188,7 @@ func (a *application) connect(ctx context.Context, req targetRequest) (target, e
}
// The message must not reveal which account the token belongs to.
if !services.MatchAccount(t.User, actual) {
return t, clierr.Wrap(clierr.Authentication, errors.New("GITEA_TOKEN does not belong to the selected account; supply its matching --user or remove the environment token to use stored credentials"))
return t, clierr.Wrap(clierr.Authentication, errEnvironmentAccount)
}
if t.User == "" {
t.UserSource = "GITEA_TOKEN authenticated account"