Compare commits
2 Commits
ef0b1916f2
...
a1cf327837
| Author | SHA1 | Date | |
|---|---|---|---|
| a1cf327837 | |||
| c31bf9d4fb |
@@ -5,8 +5,13 @@ import logoImg from "../../assets/pictures/Logo.png"
|
|||||||
import ButtonGreen from "../Buttons/ButtonGreen.jsx"
|
import ButtonGreen from "../Buttons/ButtonGreen.jsx"
|
||||||
import { FaUsers, FaPaintBrush, FaHeadset } from "react-icons/fa"
|
import { FaUsers, FaPaintBrush, FaHeadset } from "react-icons/fa"
|
||||||
import { motion } from "framer-motion"
|
import { motion } from "framer-motion"
|
||||||
|
import { isAuthenticated } from "../../hooks/useRequireAuth" // <-- added import
|
||||||
|
import { useNavigate } from "react-router-dom" // <-- NEW
|
||||||
|
|
||||||
const LandingPage = ({ onNavigateToPlay, onNavigateToAuth }) => {
|
const LandingPage = ({ onNavigateToPlay, onNavigateToAuth }) => {
|
||||||
|
const auth = isAuthenticated() // <-- check without redirect
|
||||||
|
const navigate = useNavigate() // <-- NEW
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
{/* Hero Section */}
|
{/* Hero Section */}
|
||||||
@@ -55,8 +60,15 @@ const LandingPage = ({ onNavigateToPlay, onNavigateToAuth }) => {
|
|||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
transition={{ duration: 0.7, delay: 1 }}
|
transition={{ duration: 0.7, delay: 1 }}
|
||||||
>
|
>
|
||||||
|
{/* If not authenticated show Login/Register; if authenticated show Home button */}
|
||||||
|
{!auth ? (
|
||||||
|
<>
|
||||||
<ButtonGreen text="Bejelntekezés" onClick={onNavigateToPlay} width="w-60" />
|
<ButtonGreen text="Bejelntekezés" onClick={onNavigateToPlay} width="w-60" />
|
||||||
<ButtonGreen text="Regisztráció" onClick={onNavigateToAuth} width="w-60" />
|
<ButtonGreen text="Regisztráció" onClick={onNavigateToAuth} width="w-60" />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<ButtonGreen text="Játék" onClick={() => navigate("/home")} width="w-60" />
|
||||||
|
)}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>
|
</div>
|
||||||
</motion.section>
|
</motion.section>
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ export function requireAuthSync({ key = "username", redirectTo = "/login", repla
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New: non-redirecting check for auth status
|
||||||
|
export function isAuthenticated(key = "username") {
|
||||||
|
try {
|
||||||
|
return !!localStorage.getItem(key)
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default hook: ad vissza egy [value, setValue] párt, szinkronizálja localStorage-t és átirányít, ha nincs érték
|
// Default hook: ad vissza egy [value, setValue] párt, szinkronizálja localStorage-t és átirányít, ha nincs érték
|
||||||
export default function useRequireAuth({ key = "username", redirectTo = "/login" } = {}) {
|
export default function useRequireAuth({ key = "username", redirectTo = "/login" } = {}) {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|||||||
Reference in New Issue
Block a user