Добавлено сохранение логина пользователя в куки при авторизации и отображение его в навигации. Обновлен компонент Navigation для отображения первых двух букв логина или имени по умолчанию.

This commit is contained in:
Redsandyg
2025-06-03 17:28:15 +03:00
parent af0c52dbb6
commit 0e024b00a1
2 changed files with 16 additions and 4 deletions

View File

@@ -2,6 +2,8 @@
import Link from "next/link";
import { usePathname } from "next/navigation";
import styles from "../styles/navigation.module.css";
import Cookies from "js-cookie";
import { useEffect, useState } from "react";
interface NavItem {
id: string;
@@ -17,6 +19,15 @@ const navItems: NavItem[] = [
const Navigation: React.FC = () => {
const pathname = usePathname();
const [login, setLogin] = useState<string>("");
useEffect(() => {
if (typeof document !== "undefined") {
const userLogin = Cookies.get('user_login');
if (userLogin) setLogin(userLogin);
}
}, []);
if (pathname === "/auth") return null;
return (
<nav className={styles.nav}>
@@ -37,8 +48,8 @@ const Navigation: React.FC = () => {
))}
</div>
<div className={styles.profile}>
<div className={styles.avatar}>ПП</div>
<span className={styles.profileName}>Партнер RE:Premium</span>
<div className={styles.avatar}>{login ? login.slice(0, 2).toUpperCase() : "ПП"}</div>
<span className={styles.profileName}>{login ? login : "Партнер RE:Premium"}</span>
</div>
</nav>
);