import Link from 'next/link'; import { useRouter } from 'next/router'; import { ReactNode, useState, useEffect } from 'react'; import { useHints } from '../contexts/HintContext'; import { NotificationProvider } from '../contexts/NotificationContext'; import NotificationContainer from './NotificationContainer'; type Props = { children: ReactNode }; const nav = [ // Navigation items removed - using logo for home and buttons for actions ]; export default function Layout({ children }: Props) { const router = useRouter(); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [profileDropdownOpen, setProfileDropdownOpen] = useState(false); const [isLoggedIn, setIsLoggedIn] = useState(false); const [userInfo, setUserInfo] = useState<{username: string, isAdmin: boolean} | null>(null); const { hintsVisible, toggleHints } = useHints(); // Check login status on component mount and when localStorage changes useEffect(() => { const checkLoginStatus = () => { const userData = localStorage.getItem('user'); if (userData) { try { const parsedUser = JSON.parse(userData); setIsLoggedIn(true); setUserInfo(parsedUser); } catch (error) { setIsLoggedIn(false); setUserInfo(null); } } else { setIsLoggedIn(false); setUserInfo(null); } }; // Initial check checkLoginStatus(); // Listen for storage changes (when user logs in/out in another tab) const handleStorageChange = (e: StorageEvent) => { if (e.key === 'user') { checkLoginStatus(); } }; window.addEventListener('storage', handleStorageChange); // Also check periodically in case of same-tab changes const interval = setInterval(checkLoginStatus, 1000); return () => { window.removeEventListener('storage', handleStorageChange); clearInterval(interval); }; }, []); // Close dropdown when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { const target = event.target as Element; if (profileDropdownOpen && !target.closest('.profile-dropdown')) { setProfileDropdownOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, [profileDropdownOpen]); const handleLogout = () => { localStorage.removeItem('user'); setIsLoggedIn(false); setUserInfo(null); setProfileDropdownOpen(false); router.push('/'); }; return (
{/* Logo */}
⚡
Hacksmith Shop {/* Desktop Navigation - Removed, using action buttons instead */} {/* Desktop Actions */}
{isLoggedIn ? (
{profileDropdownOpen && (
setProfileDropdownOpen(false)} className="block px-4 py-2 text-sm text-gray-300 hover:text-hacksmith-orange hover:bg-hacksmith-light-gray transition-colors rounded-t-lg" > View Profile
)}
) : ( Login )} Submit Flag
{/* Mobile Menu Button */}
{/* Mobile Menu */}
{/* Mobile navigation removed */}
{isLoggedIn ? ( <>
Welcome, {userInfo?.username}!
setMobileMenuOpen(false)} className="block w-full text-center btn-secondary flex items-center justify-center space-x-2" > {userInfo?.isAdmin ? ( ) : ( )} View Profile ) : ( setMobileMenuOpen(false)} className="block w-full text-center btn-secondary flex items-center justify-center space-x-2" > Login )} setMobileMenuOpen(false)} className="block w-full text-center btn-secondary" > Submit Flag
{children}
{/* Global Hint Toggle Button */}
{/* Company Info */}
Hacksmith Shop

The ultimate destination for blacksmithing tools and professional equipment.

{/* Quick Links */}

Quick Links

  • Home
  • Login
  • Profile
  • Submit Flag
{/* CTF Info */}

Security Challenges

  • SQL Injection
  • XSS Scripting
  • IDOR Vulnerabilities
  • File Inclusion (LFI)
  • File Upload Bypass
  • Input Validation
{/* Support */}

Support

  • Help Center
  • CTF Guide
  • Security Docs
  • Contact Us
© {new Date().getFullYear()} Hacksmith Shop. All rights reserved.
⚠ Intentionally Vulnerable for Educational Purposes
{/* Notification Container */}
); }