feat(auth): make email the unique login identifier
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

Login is now by email, not username. username still exists internally
(JWT sub claim, audit logs, Jira actor attribution, SSO provisioning all
still key off it) but is now always kept equal to email everywhere a user
is created or their email changes — never a separately-chosen value.

- User.email is now unique + NOT NULL (migration b067 backfills any
  missing/blank email from username first, so existing rows — notably
  the seeded admin, which historically had none — never violate it).
- /auth/login and the (unused but updated for consistency)
  authenticate_user() now query by email.
- create_user (legacy, unreferenced but kept) and
  create_user_without_password both derive username from email.
- update_user keeps username in sync when email changes, and rejects
  duplicate emails.
- seed.py reads ADMIN_EMAIL (new env var, wired through install.sh and
  docker-compose.prod.yml) for the initial admin; falls back to an
  email-shaped ADMIN_USERNAME or a placeholder that's flagged for the
  operator to fix.
- admin_config.py's import bundle now matches/creates users by email,
  skipping (not crashing on) entries with no email.
- sso_service.py always sets username = email for SSO-provisioned users.
- LoginPage/auth.ts updated to email input/copy (wire field name stays
  'username' — that's the OAuth2PasswordRequestForm spec, not the value).
This commit is contained in:
kitos
2026-07-23 14:39:36 +02:00
parent 0a6cb5510c
commit 504dfc52f5
21 changed files with 184 additions and 81 deletions
+7 -4
View File
@@ -2,17 +2,20 @@ import client from "./client";
import type { User } from "../types/models";
/**
* Authenticate the user.
* Authenticate the user with their email (the unique login identifier)
* and password.
*
* The backend sets an HttpOnly cookie with the JWT — no token is stored
* in JavaScript memory or localStorage.
* in JavaScript memory or localStorage. The form field is still named
* "username" on the wire — that's the OAuth2PasswordRequestForm spec's
* fixed field name, not a statement about what value it holds.
*/
export async function login(
username: string,
email: string,
password: string,
): Promise<void> {
const params = new URLSearchParams();
params.append("username", username);
params.append("username", email);
params.append("password", password);
await client.post("/auth/login", params, {
+14 -14
View File
@@ -9,7 +9,7 @@ export default function LoginPage() {
const { login, isAuthenticated } = useAuth();
const navigate = useNavigate();
const [username, setUsername] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
@@ -36,10 +36,10 @@ export default function LoginPage() {
setError(null);
setLoading(true);
try {
await login(username, password);
await login(email, password);
navigate("/dashboard", { replace: true });
} catch {
setError("Invalid username or password");
setError("Invalid email or password");
} finally {
setLoading(false);
}
@@ -103,12 +103,12 @@ export default function LoginPage() {
</p>
<form onSubmit={handleSubmit} className="space-y-3">
<input
type="text"
type="email"
required
autoFocus
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Username"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
className="w-full rounded-lg border border-gray-700 bg-gray-800 px-3 py-2 text-sm text-white placeholder-gray-500 outline-none focus:border-cyan-500 focus:ring-1 focus:ring-cyan-500"
/>
<input
@@ -141,20 +141,20 @@ export default function LoginPage() {
<form onSubmit={handleSubmit} className="space-y-5">
<div>
<label
htmlFor="username"
htmlFor="email"
className="mb-1.5 block text-sm font-medium text-gray-300"
>
Username
Email
</label>
<input
id="username"
type="text"
id="email"
type="email"
required
autoFocus
value={username}
onChange={(e) => setUsername(e.target.value)}
value={email}
onChange={(e) => setEmail(e.target.value)}
className="w-full rounded-lg border border-gray-700 bg-gray-900 px-3 py-2 text-sm text-white placeholder-gray-500 outline-none focus:border-cyan-500 focus:ring-1 focus:ring-cyan-500"
placeholder="admin"
placeholder="you@company.com"
/>
</div>