{"record":{"id":"8ed32c2aa41ffa4c","repo":"netbirdio/netbird","slug":"login-failed-v","errorCode":null,"errorMessage":"login failed: %v","messagePattern":"login failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/android/login.go","lineNumber":134,"sourceCode":"\t\t\tresultListener.OnError(err)\n\t\t} else {\n\t\t\tresultListener.OnSuccess()\n\t\t}\n\t}()\n}\n\nfunc (a *Auth) loginWithSetupKeyAndSaveConfig(setupKey string, deviceName string) error {\n\tauthClient, err := auth.NewAuth(a.ctx, a.config.PrivateKey, a.config.ManagementURL, a.config)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create auth client: %v\", err)\n\t}\n\tdefer authClient.Close()\n\n\t//nolint\n\tctxWithValues := context.WithValue(a.ctx, system.DeviceNameCtxKey, deviceName)\n\terr, _ = authClient.Login(ctxWithValues, setupKey, \"\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"login failed: %v\", err)\n\t}\n\n\treturn profilemanager.WriteOutConfig(a.cfgPath, a.config)\n}\n\n// Login try register the client on the server\nfunc (a *Auth) Login(resultListener ErrListener, urlOpener URLOpener, isAndroidTV bool) {\n\tgo func() {\n\t\terr := a.login(urlOpener, isAndroidTV)\n\t\tif err != nil {\n\t\t\tresultListener.OnError(err)\n\t\t} else {\n\t\t\tresultListener.OnSuccess()\n\t\t}\n\t}()\n}\n\nfunc (a *Auth) login(urlOpener URLOpener, isAndroidTV bool) error {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/android/login.go#L116-L152","documentation":"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).","triggerScenarios":"Wrong, expired, revoked, or usage-exhausted setup key; management rejecting the peer (posture, policy); network failure during the login RPC.","commonSituations":"Key past its usage limit or expiry date; key copied with whitespace; peer removed from the account while registering.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isLoginFailure(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"login failed:\")\n}","tryCatchPattern":"err := a.loginWithSetupKeyAndSaveConfig(setupKey, deviceName)\nif err != nil && isLoginFailure(err) {\n    // likely an invalid/expired/exhausted setup key or a management-side\n    // rejection: prompt the user for a new key instead of retrying blindly\n}","preventionTips":["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."],"tags":["android","auth","setup-key","login","management"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}