feat: complete user authentication with separate login and register pages

This commit is contained in:
Marko (Hermes Implementer)
2026-05-26 04:35:27 +00:00
parent 6867a91b67
commit fc0531395d
6 changed files with 254 additions and 5 deletions
+2
View File
@@ -0,0 +1,2 @@
# API base URL for the Django backend
VITE_API_URL=http://localhost:8000
+4 -2
View File
@@ -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
+15 -1
View File
@@ -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",