plandex-ai/plandex · warning
error validating sign in code: %v
Error message
error validating sign in code: %v
What it means
ValidateAndSignIn, when the request carries a sign-in code (IsSignInCode), validates the 6-digit PIN via db.ValidateSignInCode; any failure there (expired, wrong, or DB error) is logged and re-wrapped with this message for the SignInHandler.
Source
Thrown at app/server/handlers/auth_helpers.go:307
return accounts, nil
}
func ValidateAndSignIn(w http.ResponseWriter, r *http.Request, req shared.SignInRequest) (*shared.SessionResponse, error) {
var user *db.User
var emailVerificationId string
var signInCodeId string
var signInCodeOrgId string
var err error
isLocalMode := (os.Getenv("GOENV") == "development" && os.Getenv("LOCAL_MODE") == "1")
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)View on GitHub (pinned to e2d772072e)
Solutions
- Ask the user to re-enter the code carefully or request a new sign-in code
- Check code expiry/TTL and regenerate if elapsed
- Confirm the code wasn't already consumed (single-use codes are invalidated after success)
- Check DB health if the log line shows a query/connection error rather than invalid code
- Return a retryable 401 to the client prompting a fresh code
Example fix
// before
return nil, fmt.Errorf("error validating sign in code: %v", err)
// after
return nil, fmt.Errorf("error validating sign in code: %w", err) // %w lets callers classify invalid-code vs transient db errors Defensive patterns
Strategy: try-catch
Validate before calling
// before submitting
if len(req.Pin) != 6 || !isAllDigits(req.Pin) {
return errors.New("sign-in code must be 6 digits")
} Try / catch
user, err := ValidateAndSignIn(r.Context(), req)
if err != nil {
if strings.HasPrefix(err.Error(), "error validating sign in code") {
http.Error(w, "invalid or expired code — request a new one", http.StatusUnauthorized); return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
} Prevention
- Enforce PIN format client-side before submitting
- Check code expiry and single-use semantics before validation
- Auto-resend a fresh code after N failed attempts or on expiry
- Rate-limit code attempts and show a clear 'request new code' path instead of generic 500s
When it happens
Trigger: User submits a sign-in code via SignInHandler and db.ValidateSignInCode returns an error — the PIN is wrong/expired/already used, or the sign-in-codes lookup fails at the DB level.
Common situations: User mistypes the emailed one-time code, code expired past its TTL, code already consumed in a previous attempt, or database connectivity problems during validation.
Related errors
- error loading accounts: %v
- error signing in to new account: %v
- error selecting account: %v
- error prompting for sign in to new account: %v
- auth.Current.UserId is empty
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/0770d568f8084b4c.
Report an issue: GitHub.