fix: improve the login page UI

This commit is contained in:
2026-07-18 17:20:39 +07:00
parent 21532e0f00
commit 3ebfab2684
3 changed files with 1334 additions and 70 deletions
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
{
"version": 1,
"skills": {
"design-taste-frontend": {
"source": "Leonxlnx/taste-skill",
"sourceType": "github",
"skillPath": "skills/taste-skill/SKILL.md",
"computedHash": "6d838b246d0e35d0b53f4f23f98ba7a1dd561937e64f7d0c7553b0928e376c3e"
}
}
}
+117 -70
View File
@@ -1,7 +1,40 @@
"use client"; "use client";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { Card, Button, Input } from "@/shared/components"; import Button from "@/shared/components/Button";
import Card from "@/shared/components/Card";
import Input from "@/shared/components/Input";
import { Skeleton } from "@/shared/components/Loading";
function LoginLoadingState() {
return (
<main className="relative isolate min-h-dvh overflow-hidden bg-bg px-4 py-8 sm:px-6 lg:px-8" aria-busy="true">
<div className="landing-grid pointer-events-none absolute inset-0" aria-hidden="true" />
<div className="relative mx-auto flex min-h-[calc(100dvh-4rem)] w-full max-w-xl flex-col justify-center py-10">
<div className="mb-8 space-y-3">
<Skeleton className="h-6 w-32" />
<Skeleton className="h-12 w-64 max-w-full" />
<Skeleton className="h-5 w-80 max-w-full" />
</div>
<Card elev padding="lg" className="space-y-7">
<div className="space-y-2">
<div className="space-y-2">
<Skeleton className="h-4 w-24" />
<Skeleton className="h-7 w-32" />
</div>
</div>
<div className="space-y-5">
<Skeleton className="h-4 w-20" />
<Skeleton className="h-11 w-full" />
<Skeleton className="h-4 w-20" />
<Skeleton className="h-11 w-full" />
<Skeleton className="h-11 w-full bg-brand-500/25" />
</div>
</Card>
</div>
</main>
);
}
export default function LoginPage() { export default function LoginPage() {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
@@ -81,7 +114,7 @@ export default function LoginPage() {
if (data.retryAfter) setRetryAfter(Number(data.retryAfter)); if (data.retryAfter) setRetryAfter(Number(data.retryAfter));
} }
} catch (err) { } catch (err) {
setError("An error occurred. Please try again."); setError("We couldn't sign you in. Please try again.");
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -105,7 +138,7 @@ export default function LoginPage() {
setError(data.error || "Failed to set password"); setError(data.error || "Failed to set password");
} }
} catch (err) { } catch (err) {
setError("An error occurred. Please try again."); setError("We couldn't set your password. Please try again.");
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -120,139 +153,153 @@ export default function LoginPage() {
// Show loading state while checking password // Show loading state while checking password
if (hasPassword === null) { if (hasPassword === null) {
return ( return <LoginLoadingState />;
<div className="min-h-screen flex items-center justify-center bg-bg p-4">
<div className="text-center">
<div className="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
<p className="text-text-muted mt-4">Loading...</p>
</div>
</div>
);
} }
return ( return (
<div className="min-h-screen flex items-center justify-center bg-bg p-4 relative overflow-hidden"> <main className="relative isolate min-h-dvh overflow-hidden bg-bg px-4 py-8 sm:px-6 lg:px-8">
{/* Faint grid background */} <div className="landing-grid pointer-events-none absolute inset-0" aria-hidden="true" />
<div className="landing-grid absolute inset-0 pointer-events-none" aria-hidden="true" /> <div className="relative mx-auto flex min-h-[calc(100dvh-4rem)] w-full max-w-xl flex-col justify-center py-10">
<div className="relative z-10 w-full max-w-md"> <header className="mb-8">
<div className="text-center mb-8"> <p className="mb-5 text-sm font-semibold tracking-[-0.02em] text-text-main">9Router (Remake)</p>
<h1 className="text-3xl font-bold text-primary mb-2">9Router (Remake)</h1> <h1 className="max-w-none text-[clamp(2.125rem,6vw,3rem)] font-semibold leading-[0.96] tracking-[-0.065em] text-text-main">
<p className="text-xs text-text-muted mb-2">Forked from the official 9Router project and remade by Nezumi.</p> Route your models from one secure workspace.
<p className="text-text-muted"> </h1>
<p className="mt-4 max-w-[38ch] text-pretty text-sm leading-6 text-text-muted sm:text-base">
{authMode === "oidc" && oidcConfigured {authMode === "oidc" && oidcConfigured
? "Sign in with your OIDC provider to access the dashboard" ? "Sign in with your identity provider to access the dashboard."
: "Enter your username and password to access the dashboard"} : "Enter your administrator credentials to access the dashboard."}
</p> </p>
</div> </header>
<Card elev padding="lg">
<div className="mb-7">
<div>
<p className="text-sm font-medium text-text-muted">Dashboard access</p>
<h2 className="mt-1 text-2xl font-semibold tracking-[-0.04em] text-text-main">
{mustChange ? "Set a new password" : "Sign in"}
</h2>
</div>
</div>
<Card>
{mustChange ? ( {mustChange ? (
<form onSubmit={handleSetNewPassword} className="flex flex-col gap-4"> <form onSubmit={handleSetNewPassword} className="flex flex-col gap-5">
<p className="text-sm text-amber-600 dark:text-amber-400 text-center"> <div className="rounded-[10px] border border-warning/25 bg-warning/10 p-3 text-sm leading-5 text-warning">
Set a new password before accessing the dashboard remotely. <p>Set a new password before accessing the dashboard remotely.</p>
</p> </div>
<div className="flex flex-col gap-2"> <div>
<label className="text-sm font-medium">New password</label>
<Input <Input
label="New password"
type="password" type="password"
placeholder="Enter new password" placeholder="Enter new password"
value={newPassword} value={newPassword}
onChange={(e) => setNewPassword(e.target.value)} onChange={(e) => setNewPassword(e.target.value)}
error={error || undefined}
required required
autoFocus autoFocus
/> />
{error && <p className="text-xs text-red-500">{error}</p>}
</div> </div>
<Button type="submit" variant="primary" className="w-full" loading={loading} disabled={!newPassword}> <Button type="submit" variant="primary" fullWidth loading={loading} disabled={!newPassword}>
Set password Set password
</Button> </Button>
</form> </form>
) : ( ) : (
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-5">
{oidcAvailable && ( {oidcAvailable && (
<Button type="button" variant="primary" className="w-full" onClick={handleOidcLogin}> <Button
type="button"
variant={passwordAvailable ? "outline" : "primary"}
fullWidth
onClick={handleOidcLogin}
>
{oidcLoginLabel} {oidcLoginLabel}
</Button> </Button>
)} )}
{oidcAvailable && passwordAvailable && <div className="h-px bg-border/60" />} {oidcAvailable && passwordAvailable && (
<div className="flex items-center gap-3" aria-hidden="true">
<div className="h-px flex-1 bg-border" />
<span className="text-xs text-text-subtle">or use a password</span>
<div className="h-px flex-1 bg-border" />
</div>
)}
{passwordAvailable ? ( {passwordAvailable ? (
<form onSubmit={handleLogin} className="flex flex-col gap-4"> <form onSubmit={handleLogin} className="flex flex-col gap-5">
{((authMode === "oidc" && !oidcConfigured) || (authMode === "both" && !oidcConfigured)) && ( {((authMode === "oidc" && !oidcConfigured) || (authMode === "both" && !oidcConfigured)) && (
<p className="text-xs text-amber-600 dark:text-amber-400 text-center"> <div className="rounded-[10px] border border-warning/25 bg-warning/10 p-3 text-xs leading-5 text-warning">
OIDC login is enabled, but the issuer/client fields are not configured yet. Password login is still available for recovery. <p>OIDC is enabled but not configured. Password login remains available for recovery.</p>
</p> </div>
)} )}
{authMode === "both" && oidcConfigured && ( {authMode === "both" && oidcConfigured && (
<p className="text-xs text-text-muted text-center"> <p className="text-xs leading-5 text-text-muted">
Password and OIDC login are both enabled. Password and identity-provider sign-in are both available.
</p> </p>
)} )}
<div className="flex flex-col gap-2"> <Input
<label className="text-sm font-medium">Username</label> label="Username"
<Input type="text"
type="text" placeholder="Enter username"
placeholder="Enter username" value={username}
value={username} onChange={(e) => setUsername(e.target.value)}
onChange={(e) => setUsername(e.target.value)} required
required autoComplete="username"
autoComplete="username" autoFocus={!oidcAvailable}
autoFocus={!oidcAvailable} />
/>
</div>
<div className="flex flex-col gap-2"> <div className="space-y-2">
<label className="text-sm font-medium">Password</label>
<Input <Input
label="Password"
type="password" type="password"
placeholder="Enter password" placeholder="Enter password"
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
error={error || undefined}
required required
autoComplete="current-password" autoComplete="current-password"
/> />
{error && <p className="text-xs text-red-500">{error}</p>}
{retryAfter > 0 && ( {retryAfter > 0 && (
<p className="text-xs text-amber-600 dark:text-amber-400"> <p className="text-xs text-warning" role="status" aria-live="polite">
Locked. Retry in <span className="font-mono">{retryAfter}s</span>. Locked. Retry in <span className="font-mono tabular-nums">{retryAfter}s</span>.
</p> </p>
)} )}
{resetHint && ( {resetHint && (
<p className="text-xs text-text-muted"> <div className="rounded-[10px] border border-border-subtle bg-surface-2/70 p-3 text-xs leading-5 text-text-muted">
Forgot password? Open <code className="bg-sidebar px-1 rounded">9router</code> CLI on the host <b>Settings</b> <b>Reset Password to Default</b>. <p>
</p> Reset the password from the host: open <code className="rounded bg-bg px-1.5 py-0.5 font-mono text-text-main">9router</code>, then go to <strong className="font-medium text-text-main">Settings</strong> and select <strong className="font-medium text-text-main">Reset Password to Default</strong>.
</p>
</div>
)} )}
</div> </div>
<Button <Button
type="submit" type="submit"
variant="primary" variant="primary"
className="w-full" fullWidth
loading={loading} loading={loading}
disabled={retryAfter > 0} disabled={retryAfter > 0}
> >
{retryAfter > 0 ? `Wait ${retryAfter}s` : "Login"} {retryAfter > 0 ? `Wait ${retryAfter}s` : "Sign in"}
</Button> </Button>
<p className="text-xs text-center text-text-muted mt-2">
Default administrator login: <code className="bg-sidebar px-1 rounded">admin</code> / <code className="bg-sidebar px-1 rounded">123456</code>
</p>
{hasPassword === false && ( {hasPassword === false && (
<p className="text-xs text-center text-amber-600 dark:text-amber-400"> <div className="rounded-[10px] border border-warning/25 bg-warning/10 p-3 text-xs leading-5 text-warning">
Security risk: no password set. You will be asked to set one when logging in remotely. <p>No password is set. Remote sign-in requires you to create one before accessing the dashboard.</p>
</p> </div>
)} )}
</form> </form>
) : ( ) : (
error && <p className="text-xs text-red-500">{error}</p> error && <p className="text-xs text-danger" role="alert">{error}</p>
)} )}
</div> </div>
)} )}
</Card> </Card>
<footer className="mt-6 max-w-md text-xs leading-5 text-text-subtle">
Forked from the official 9Router project and remade by Nezumi.
</footer>
</div> </div>
</div> </main>
); );
} }