feat: complete user authentication with separate login and register pages
This commit is contained in:
@@ -98,8 +98,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const register = useCallback(async (payload: RegisterPayload) => {
|
||||
dispatch({ type: "AUTH_START" });
|
||||
try {
|
||||
const user = await registerUser(payload);
|
||||
dispatch({ type: "AUTH_SUCCESS", payload: user });
|
||||
await registerUser(payload);
|
||||
// Registration succeeded — the page component handles redirect to /login.
|
||||
// Set isLoading=false by clearing auth state (no auto-authentication).
|
||||
dispatch({ type: "LOGOUT" });
|
||||
} catch (err: unknown) {
|
||||
const message =
|
||||
err instanceof Error
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { useState, type FormEvent, type ChangeEvent } from "react";
|
||||
import { useNavigate, Link } from "react-router-dom";
|
||||
import { useNavigate, useLocation, Link } from "react-router-dom";
|
||||
import { useAuth } from "../contexts/AuthContext";
|
||||
|
||||
export default function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { state, login, clearError } = useAuth();
|
||||
|
||||
const successMessage = (location.state as { message?: string } | null)
|
||||
?.message;
|
||||
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
@@ -35,6 +39,7 @@ export default function LoginPage() {
|
||||
<p style={styles.subtitle}>Welcome back to Job Tracker</p>
|
||||
|
||||
{state.error && <div style={styles.error}>{state.error}</div>}
|
||||
{successMessage && <div style={styles.success}>{successMessage}</div>}
|
||||
|
||||
<form onSubmit={handleSubmit} style={styles.form}>
|
||||
<div style={styles.field}>
|
||||
@@ -165,6 +170,15 @@ const styles: Record<string, React.CSSProperties> = {
|
||||
fontSize: "0.85rem",
|
||||
marginBottom: "0.5rem",
|
||||
},
|
||||
success: {
|
||||
backgroundColor: "#f0fdf4",
|
||||
color: "#166534",
|
||||
border: "1px solid #bbf7d0",
|
||||
borderRadius: "6px",
|
||||
padding: "0.5rem 0.75rem",
|
||||
fontSize: "0.85rem",
|
||||
marginBottom: "0.5rem",
|
||||
},
|
||||
footer: {
|
||||
marginTop: "1.25rem",
|
||||
textAlign: "center",
|
||||
|
||||
Reference in New Issue
Block a user