netbirdio/netbird · error
login failed: %v
Error message
login failed: %v
What it means
In setup-key login, after the auth client is created, authClient.Login(ctxWithValues, setupKey, "") performs registration against management. A rejected or failed login is wrapped as this error. The context carries the device name via system.DeviceNameCtxKey, and the config is only persisted on success (WriteOutConfig runs after).
Source
Thrown at client/android/login.go:134
resultListener.OnError(err)
} else {
resultListener.OnSuccess()
}
}()
}
func (a *Auth) loginWithSetupKeyAndSaveConfig(setupKey string, deviceName string) error {
authClient, err := auth.NewAuth(a.ctx, a.config.PrivateKey, a.config.ManagementURL, a.config)
if err != nil {
return fmt.Errorf("failed to create auth client: %v", err)
}
defer authClient.Close()
//nolint
ctxWithValues := context.WithValue(a.ctx, system.DeviceNameCtxKey, deviceName)
err, _ = authClient.Login(ctxWithValues, setupKey, "")
if err != nil {
return fmt.Errorf("login failed: %v", err)
}
return profilemanager.WriteOutConfig(a.cfgPath, a.config)
}
// Login try register the client on the server
func (a *Auth) Login(resultListener ErrListener, urlOpener URLOpener, isAndroidTV bool) {
go func() {
err := a.login(urlOpener, isAndroidTV)
if err != nil {
resultListener.OnError(err)
} else {
resultListener.OnSuccess()
}
}()
}
func (a *Auth) login(urlOpener URLOpener, isAndroidTV bool) error {View on GitHub (pinned to 93e97f4bf1)
Solutions
- Verify the setup key is valid, unexpired, and under its usage limit in the management dashboard.
- Re-copy the key carefully (no leading/trailing whitespace) and retry.
- Check management logs for the rejection reason if the key itself looks valid.
Defensive patterns
Strategy: try-catch
Type guard
func isLoginFailure(err error) bool {
return err != nil && strings.HasPrefix(err.Error(), "login failed:")
} Try / catch
err := a.loginWithSetupKeyAndSaveConfig(setupKey, deviceName)
if err != nil && isLoginFailure(err) {
// likely an invalid/expired/exhausted setup key or a management-side
// rejection: prompt the user for a new key instead of retrying blindly
} Prevention
- Trim whitespace from pasted setup keys before submitting.
- Check key expiry and usage limits in the dashboard before distributing keys.
- Config is only written on success (WriteOutConfig runs after Login), so a failed login leaves no partial state to clean up.
When it happens
Trigger: Wrong, expired, revoked, or usage-exhausted setup key; management rejecting the peer (posture, policy); network failure during the login RPC.
Common situations: Key past its usage limit or expiry date; key copied with whitespace; peer removed from the account while registering.
Related errors
- failed to create auth client: %v
- failed to check login requirement: %v
- interactive sso login failed: %v
- failed to create auth client: %v
- failed to check SSO support: %v
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/8ed32c2aa41ffa4c.
Report an issue: GitHub.