Implement user authentication and account pages
Adds AuthContext with Orval API integration, user login/logout/register flows, and account settings page. Refactors navigation and layouts to use authentication context. Introduces new account-related pages (Login, Register, Logout, AccountSettings), updates PrivateRoute to use AuthContext, and improves error handling in Downloader. Removes obsolete context example and adds comprehensive usage documentation for AuthContext.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import {
|
||||
FaUserCircle,
|
||||
FaSignOutAlt,
|
||||
@@ -14,21 +15,18 @@ import {
|
||||
FaHandsHelping,
|
||||
} from "react-icons/fa";
|
||||
import {FaClapperboard, FaCubes} from "react-icons/fa6";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import styles from "./navbar.module.css";
|
||||
|
||||
export interface User {
|
||||
username: string;
|
||||
email?: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
|
||||
interface NavbarProps {
|
||||
user: User | null;
|
||||
onLogin: () => void;
|
||||
onLogout: () => void;
|
||||
}
|
||||
|
||||
export default function Navbar({ user, onLogin, onLogout }: NavbarProps) {
|
||||
export default function Navbar() {
|
||||
const { user, isAuthenticated, logout } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogin = () => navigate("/login");
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
navigate("/");
|
||||
};
|
||||
const [mobileMenu, setMobileMenu] = useState(false);
|
||||
const navRef = useRef<HTMLElement | null>(null);
|
||||
|
||||
@@ -114,8 +112,8 @@ export default function Navbar({ user, onLogin, onLogout }: NavbarProps) {
|
||||
<a className={styles.linkSimple} href="#contacts"><FaGlobe className={styles.iconSmall}/> Kontakt</a>
|
||||
|
||||
{/* right: user area */}
|
||||
{!user ? (
|
||||
<a className={styles.linkSimple} onClick={onLogin} aria-label="Přihlásit">
|
||||
{!isAuthenticated ? (
|
||||
<a className={styles.linkSimple} onClick={handleLogin} aria-label="Přihlásit">
|
||||
<FaSignInAlt className={styles.iconSmall} />
|
||||
</a>
|
||||
) : (
|
||||
@@ -138,7 +136,7 @@ export default function Navbar({ user, onLogin, onLogout }: NavbarProps) {
|
||||
<a href="/me/settings" role="menuitem">Nastavení</a>
|
||||
<a href="/me/billing" role="menuitem">Platby</a>
|
||||
|
||||
<button className={styles.logoutBtn} onClick={onLogout} role="menuitem">
|
||||
<button className={styles.logoutBtn} onClick={handleLogout} role="menuitem">
|
||||
<FaSignOutAlt className={styles.iconSmall} /> Odhlásit se
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user