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