#21: guard the web surfaces and connect them to the auth service
Three separate gaps, all of which made the F4 interface non-functional or unprotected: The admin console rendered for anyone. There was no middleware and no guard in the layout, so /admin/dashboard returned 200 unauthenticated - only its data calls failed. middleware.ts now redirects both surfaces to their login when the session cookie is missing, expired, carries the wrong audience, or is a pre-MFA challenge token. It reads the claims without verifying the signature on purpose: the signing key belongs to the auth service and must not reach the browser bundle. That is sound because this is not the boundary - every /api/v1 request is verified for real upstream. Nothing served /api/v1/*. next.config.ts had no rewrites and there were no route handlers, so every call the pages made 404'd against the Next server, while AUTH_SERVICE_URL sat unused. A catch-all route now proxies to the auth service, forwarding the client address and preserving multiple Set-Cookie headers, which logout needs to clear both surfaces. Session cookies also move to Path=/, since a cookie pinned to /user or /admin was never sent with the /api/v1 requests that needed it. i18n existed only as files. The three bundles had perfect key parity and real translations, but no library, no imports and no switcher: the UI was hardcoded English and i18n.test.ts compared keys while the feature was absent. There is now a provider, a hook, a language switcher, and server-side Accept-Language negotiation that honours q-values and matches a bare "pt" to pt-BR. Logins, both layouts and the settings screen consume it; the admin pages still have English titles. The settings screen invented app passwords in the browser with Math.random and never stored them. It now calls the API, which returns the password once and keeps only its hash. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
833dc76c2e
commit
132cecd41c
16 files changed
+535
-43
No files matched your search
@@ -2,8 +2,10 @@
|
||||
|
||||
import React, { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useTranslations } from "../../../../i18n/provider";
|
||||
|
||||
export default function AdminLoginPage() {
|
||||
const t = useTranslations();
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [mfaCode, setMfaCode] = useState("");
|
||||
@@ -59,7 +61,7 @@ export default function AdminLoginPage() {
|
||||
⚙
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-white">Management Console</h1>
|
||||
<h1 className="text-xl font-bold text-white">{t("auth.adminLoginTitle")}</h1>
|
||||
<p className="text-xs text-slate-400">Surface: /admin/* (Cookie: Path=/admin, MFA Mandatory)</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -74,7 +76,7 @@ export default function AdminLoginPage() {
|
||||
{!challengeToken ? (
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">Administrator Email</label>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">{t("auth.emailLabel")}</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
@@ -86,7 +88,7 @@ export default function AdminLoginPage() {
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">Password</label>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">{t("auth.passwordLabel")}</label>
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
@@ -100,9 +102,9 @@ export default function AdminLoginPage() {
|
||||
) : (
|
||||
<div>
|
||||
<div className="p-3 mb-4 rounded-lg bg-emerald-500/10 border border-emerald-500/30 text-emerald-300 text-xs">
|
||||
Mandatory Admin 2FA Requirement (PLAN.md ADR-008). Enter your 6-digit TOTP code.
|
||||
{t("auth.mfaRequired")}
|
||||
</div>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">Admin 2FA Code (6 Digits)</label>
|
||||
<label className="block text-xs font-medium text-slate-300 mb-1">{t("auth.totpCodeLabel")}</label>
|
||||
<input
|
||||
type="text"
|
||||
value={mfaCode}
|
||||
@@ -120,7 +122,7 @@ export default function AdminLoginPage() {
|
||||
disabled={loading}
|
||||
className="w-full py-3 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-medium transition-colors shadow-lg shadow-emerald-600/20 disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Verifying Admin Credentials..." : challengeToken ? "Verify Admin 2FA" : "Sign In to Admin Console"}
|
||||
{loading ? t("common.loading") : challengeToken ? t("auth.verifyCodeButton") : t("auth.signInButton")}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
Reference in new issue
Block a user