plandex-ai/plandex · error

user not found

Error message

user not found

What it means

ValidateAndSignIn, sign-in-code branch: db.GetUser(res.UserId) returned nil for the user id stored on a validated sign-in code. The code was valid but the user record was deleted — an orphaned sign-in code.

Source

Thrown at app/server/handlers/auth_helpers.go:319

	if req.IsSignInCode {
		res, err := db.ValidateSignInCode(req.Pin)

		if err != nil {
			log.Printf("Error validating sign in code: %v\n", err)
			return nil, fmt.Errorf("error validating sign in code: %v", err)
		}

		user, err = db.GetUser(res.UserId)

		if err != nil {
			log.Printf("Error getting user: %v\n", err)
			return nil, fmt.Errorf("error getting user: %v", err)
		}

		if user == nil {
			log.Printf("User not found for id: %v\n", res.UserId)
			return nil, fmt.Errorf("user not found")
		}

		signInCodeId = res.Id
		signInCodeOrgId = res.OrgId
	} else {
		req.Email = strings.ToLower(req.Email)
		user, err = db.GetUserByEmail(req.Email)

		if err != nil {
			log.Printf("Error getting user: %v\n", err)
			return nil, fmt.Errorf("error getting user: %v", err)
		}

		if user == nil {
			log.Printf("User not found for email: %v\n", req.Email)
			return nil, fmt.Errorf("not found")
		}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Delete or regenerate the sign-in code; have the user restart the sign-in flow
  2. Check for user-deletion jobs or cascades that leave orphaned sign-in codes
  3. Verify the server is pointed at the expected database/environment
  4. Log res.UserId and confirm the row exists directly in the users table

Example fix

// before
if user == nil {
	return nil, fmt.Errorf("user not found")
}
// after
if user == nil {
	log.Printf("orphaned sign-in code userId=%v", res.UserId)
	return nil, fmt.Errorf("user not found")
}
Defensive patterns

Strategy: validation

Validate before calling

// before redeeming codes, clean orphans periodically
SELECT c.id FROM sign_in_codes c LEFT JOIN users u ON u.id = c.user_id WHERE u.id IS NULL;

Type guard

func isOrphanedCode(res *db.ValidateCodeResult) bool {
	u, _ := db.GetUser(res.UserId)
	return u == nil
}

Try / catch

user, err := ValidateAndSignIn(w, r, req)
if err != nil {
	if err.Error() == "user not found" {
		http.Error(w, "this sign-in code is no longer valid, restart sign-in", http.StatusGone)
		return
	}
	http.Error(w, err.Error(), http.StatusUnauthorized)
}

Prevention

When it happens

Trigger: Client redeems a sign-in code whose res.UserId points at a user row that no longer exists; db.GetUser returns (nil, nil).

Common situations: User deleted after the sign-in code was issued; cross-environment DB (staging code against prod data); user purged by a cleanup job while codes persist.

Understand the failure class

Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/03cc2794bb5590ee. Report an issue: GitHub.