{"record":{"id":"95806afcbc3005a5","repo":"juanfont/headscale","slug":"finding-user-w","errorCode":null,"errorMessage":"finding user: %w","messagePattern":"finding user: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/state/state.go","lineNumber":2220,"sourceCode":"}\n\n// HandleNodeFromAuthPath handles node registration through authentication flow (like OIDC).\nfunc (s *State) HandleNodeFromAuthPath(\n\tauthID types.AuthID,\n\tuserID types.UserID,\n\texpiry *time.Time,\n\tregistrationMethod string,\n) (types.NodeView, change.Change, error) {\n\t// Get the registration entry from cache\n\tregEntry, ok := s.GetAuthCacheEntry(authID)\n\tif !ok {\n\t\treturn types.NodeView{}, change.Change{}, hsdb.ErrNodeNotFoundRegistrationCache\n\t}\n\n\t// Get the user\n\tuser, err := s.db.GetUserByID(userID)\n\tif err != nil {\n\t\treturn types.NodeView{}, change.Change{}, fmt.Errorf(\"finding user: %w\", err)\n\t}\n\n\tregData := regEntry.RegistrationData()\n\n\t// Hostname was already validated/normalised at producer time. Build\n\t// the initial Hostinfo from the cached client-supplied Hostinfo (or\n\t// an empty stub if the client did not send one).\n\thostname := regData.Hostname\n\n\thostinfo := &tailcfg.Hostinfo{}\n\tif regData.Hostinfo != nil {\n\t\thostinfo = regData.Hostinfo.Clone()\n\t}\n\n\thostinfo.Hostname = hostname\n\n\t// Lookup existing nodes\n\tmachineKey := regData.MachineKey","sourceCodeStart":2202,"sourceCodeEnd":2238,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/state/state.go#L2202-L2238","documentation":"During the auth callback (OIDC/interactive login), looking up the user selected for the new registration failed: s.db.GetUserByID(userID) errored. The registration cache entry was already fetched successfully, so this is purely a user-table read failure or a missing user record.","triggerScenarios":"CompleteRegisterWithAuthKey/auth callback invoked with a userID that does not exist (user deleted between login start and callback), or the DB read fails outright — connection dropped, table locked, Postgres failover.","commonSituations":"Admin deletes a user while that user's OIDC login is in flight; long-lived browser login page resumed after the user was removed; transient DB outage at callback time.","solutions":["Confirm the user still exists: `headscale users list`","If deleted, restart the login flow for a valid user","For DB read errors, restore connectivity and retry — the client re-initiates registration cleanly"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the user exists before completing the callback:\nif _, err := db.GetUserByID(userID); err != nil {\n    http.Redirect(w, r, \"/register?error=user_missing\", http.StatusTemporaryRedirect)\n    return\n}","typeGuard":null,"tryCatchPattern":"node, ch, err := s.CompleteRegistration(authID, userID, ...)\nif err != nil && strings.Contains(err.Error(), \"finding user\") {\n    // user deleted mid-login; restart flow with a fresh auth URL\n    s.authCache.Remove(authID)\n    renderError(w, \"user no longer exists; start a new login\")\n    return\n}","preventionTips":["Do not delete users with in-flight logins; expire their sessions first","Keep auth-cache TTLs short so stale callbacks fail fast","Distinguish this from hsdb.ErrNodeNotFoundRegistrationCache (missing reg entry) in handling"],"tags":["oidc","users","database","registration","go"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}