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

+10
View File
@@ -801,6 +801,16 @@ $ tea auth token --host gitea.com --user alice`,
if instance, err := settings.ResolveHost(a.tokenInstance(), s.Hosts.Hosts); err != nil || instance != t.Host {
token = ""
}
if token != "" && t.User != "" {
// Like connect, print the environment token only for the account it authenticates.
actual, err := services.CurrentAccount(cmd.Context(), a.deps.Client(t.Host, token, t.host.Insecure))
if err != nil {
return err
}
if !services.MatchAccount(t.User, actual) {
return clierr.Wrap(clierr.Authentication, errEnvironmentAccount)
}
}
if token == "" {
account, exists := t.host.Users[t.User]
switch {