plandex-ai/plandex · error · http

Error creating sign in code:

Error message

Error creating sign in code: 

What it means

This error is returned by CreateSignInCodeHandler when db.CreateSignInCode fails to persist the sign-in code (user id, org id, SHA-256-hashed PIN). The handler responds with HTTP 500 prefixed 'Error creating sign in code: '. The PIN was generated fine but the database write failed, so the code cannot be redeemed.

Source

Thrown at app/server/handlers/sessions.go:201

	}

	// create pin - 6 alphanumeric characters
	pinBytes, err := shared.GetRandomAlphanumeric(6)
	if err != nil {
		log.Printf("Error generating random pin: %v\n", err)
		http.Error(w, "Error generating random pin: "+err.Error(), http.StatusInternalServerError)
		return
	}

	// get sha256 hash of pin
	hashBytes := sha256.Sum256(pinBytes)
	pinHash := hex.EncodeToString(hashBytes[:])

	err = db.CreateSignInCode(auth.User.Id, auth.OrgId, pinHash)

	if err != nil {
		log.Printf("Error creating sign in code: %v\n", err)
		http.Error(w, "Error creating sign in code: "+err.Error(), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully created sign in code")

	// return the pin as a response
	w.Write(pinBytes)
}

func SignInHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received request for SignInHandler")

	// read the request body
	body, err := io.ReadAll(r.Body)
	if err != nil {
		log.Printf("Error reading request body: %v\n", err)
		http.Error(w, "Error reading request body: "+err.Error(), http.StatusInternalServerError)
		return

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the log for the wrapped underlying DB error
  2. Verify database connectivity and env configuration
  3. Run pending migrations so the sign_in_codes table exists
  4. Check for constraint/foreign-key issues with the user's org id
  5. Retry after the database is healthy

Example fix

// before
err = db.CreateSignInCode(auth.User.Id, auth.OrgId, pinHash)
if err != nil {
	http.Error(w, "Error creating sign in code: "+err.Error(), http.StatusInternalServerError)
	return
}
// after: log full context and only retry transient failures
err = db.CreateSignInCode(auth.User.Id, auth.OrgId, pinHash)
if err != nil {
	log.Printf("Error creating sign in code (user=%s org=%s): %v\n", auth.User.Id, auth.OrgId, err)
	http.Error(w, "Error creating sign in code: "+err.Error(), http.StatusInternalServerError)
	return
}
Defensive patterns

Strategy: retry

Validate before calling

// confirm backend health before requesting a sign-in code
resp, err := http.Get(baseURL + "/health")
if err != nil || resp.StatusCode != 200 {
	return fmt.Errorf("backend/database unavailable: %v", err)
}

Try / catch

// client: bounded retry on 500 for transient DB issues
resp, err := http.Post(url, "application/json", body)
if err != nil { return err }
if resp.StatusCode == http.StatusInternalServerError {
	time.Sleep(2 * time.Second)
	return createSignInCode() // retry once or twice
}

Prevention

When it happens

Trigger: POST to the sign-in-code endpoint after successful authentication when the DB insert in db.CreateSignInCode fails: database unavailable, constraint violation on user/org, missing table from unmigrated schema, or connection limits.

Common situations: Postgres not running or misconfigured env in local development; sign_in_codes table missing after a migration skip; foreign key failures for the org id; database disk or connection exhaustion in production.

Related errors


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