Remove auth form reload and keep SPA navigation
This commit is contained in:
@@ -262,6 +262,7 @@ function SetupPage({ onDone }: { onDone: () => Promise<void> }) {
|
||||
action="Create admin"
|
||||
onSubmit={async (fd) => {
|
||||
await api.request('/api/setup', { method: 'POST', body: JSON.stringify(Object.fromEntries(fd)) });
|
||||
nav('/admin');
|
||||
await onDone();
|
||||
}}
|
||||
fields={['username', 'password']}
|
||||
@@ -276,7 +277,6 @@ function LoginPage({ onDone }: { onDone: () => Promise<void> }) {
|
||||
action="Sign in"
|
||||
onSubmit={async (fd) => {
|
||||
await api.request('/api/login', { method: 'POST', body: JSON.stringify(Object.fromEntries(fd)) });
|
||||
nav('/');
|
||||
await onDone();
|
||||
}}
|
||||
fields={['username', 'password']}
|
||||
@@ -295,20 +295,28 @@ function AuthCard({
|
||||
fields: string[];
|
||||
onSubmit: (fd: FormData) => Promise<void>;
|
||||
}) {
|
||||
const [submitError, setSubmitError] = useState<string | null>(null);
|
||||
|
||||
return (
|
||||
<div className="grid min-h-screen place-items-center p-4">
|
||||
<form
|
||||
className="panel w-full max-w-sm space-y-3"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
await onSubmit(new FormData(e.currentTarget));
|
||||
location.reload();
|
||||
setSubmitError(null);
|
||||
try {
|
||||
await onSubmit(new FormData(e.currentTarget));
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
setSubmitError(message || 'Request failed. Please try again.');
|
||||
}
|
||||
}}
|
||||
>
|
||||
<h1 className="title-sm">{title}</h1>
|
||||
{fields.map((f) => (
|
||||
<input key={f} name={f} type={f === 'password' ? 'password' : 'text'} className="input" placeholder={f} required />
|
||||
))}
|
||||
{submitError ? <p className="text-xs text-rose-400">{submitError}</p> : null}
|
||||
<button className="btn-subtle w-full" type="submit">{action}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user