refactor(api): one password rule, one hash, one unique-violation check (#8002)

The length check and bcrypt call were copied into sign-up, reset,
change and both admin paths; the unique-violation test into three api
handlers and the library. checkNewPassword and hashPassword now sit in
api/prelude.go, and db.IsUniqueViolation serves api and library. The
taken-username and taken-email conflicts now carry a message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 12:45:18 -05:00
co-authored by Claude Opus 5.5
parent cfdd6b916f
commit 074d9ffb0e
10 changed files with 66 additions and 55 deletions
+17
View File
@@ -0,0 +1,17 @@
package db
import (
"errors"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"
)
// IsUniqueViolation reports whether err is Postgres refusing a row because
// another row already holds the same unique value: a username or email
// that is taken, or a second album row claiming one MBID. Callers use it to
// tell "that already exists" apart from a write that failed.
func IsUniqueViolation(err error) bool {
var pgErr *pgconn.PgError
return errors.As(err, &pgErr) && pgErr.Code == pgerrcode.UniqueViolation
}