Harden auth and security controls with session auth and docs
This commit is contained in:
71
frontend/src/components/LoginScreen.tsx
Normal file
71
frontend/src/components/LoginScreen.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Login screen for session-based authentication before loading protected application views.
|
||||
*/
|
||||
import { FormEvent, useState } from 'react';
|
||||
import type { JSX } from 'react';
|
||||
|
||||
interface LoginScreenProps {
|
||||
error: string | null;
|
||||
isSubmitting: boolean;
|
||||
onSubmit: (username: string, password: string) => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders credential form used to issue per-user API bearer sessions.
|
||||
*/
|
||||
export default function LoginScreen({
|
||||
error,
|
||||
isSubmitting,
|
||||
onSubmit,
|
||||
}: LoginScreenProps): JSX.Element {
|
||||
const [username, setUsername] = useState<string>('');
|
||||
const [password, setPassword] = useState<string>('');
|
||||
|
||||
/**
|
||||
* Submits credentials and leaves result handling to parent application orchestration.
|
||||
*/
|
||||
const handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
|
||||
event.preventDefault();
|
||||
if (isSubmitting) {
|
||||
return;
|
||||
}
|
||||
void onSubmit(username, password);
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="auth-shell">
|
||||
<section className="auth-card">
|
||||
<h1>LedgerDock</h1>
|
||||
<p>Sign in with your account to access documents and role-scoped controls.</p>
|
||||
<form onSubmit={handleSubmit} className="auth-form">
|
||||
<label>
|
||||
Username
|
||||
<input
|
||||
type="text"
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Password
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={isSubmitting}>
|
||||
{isSubmitting ? 'Signing In...' : 'Sign In'}
|
||||
</button>
|
||||
</form>
|
||||
{error && <p className="error-banner">{error}</p>}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user