diff --git a/app/(main)/lottery/page.tsx b/app/(main)/lottery/page.tsx index 3cab13e..def0308 100644 --- a/app/(main)/lottery/page.tsx +++ b/app/(main)/lottery/page.tsx @@ -29,7 +29,6 @@ const LotteryPage = () => { .then((response) => { if (response.errorMessage) { // If authentication fails, redirect to the auth page - console.log("lotter/", response); router.replace("/lottery/auth"); } else { // ✅ Set the authenticated state @@ -44,6 +43,10 @@ const LotteryPage = () => { } }, [setAuth]); + if (!lotteryData?.errorMessage) { + router.replace("/lottery/auth"); + } + return (
diff --git a/components/lottery/auth/ProtectedRoute.tsx b/components/lottery/auth/ProtectedRoute.tsx index 3366767..98ce676 100644 --- a/components/lottery/auth/ProtectedRoute.tsx +++ b/components/lottery/auth/ProtectedRoute.tsx @@ -1,9 +1,9 @@ -'use client'; +"use client"; -import { useEffect, useState } from 'react'; -import { useRouter } from 'next/navigation'; -import { useLotteryAuth } from '@/store/useLotteryAuth'; -import { Queries } from '@/api/queries'; +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import { useLotteryAuth } from "@/store/useLotteryAuth"; +import { Queries } from "@/api/queries"; const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { const router = useRouter(); @@ -13,8 +13,8 @@ const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { useEffect(() => { const checkAuth = async () => { // ✅ Check credentials from localStorage - const phone = localStorage.getItem('lotteryPhone'); - const code = localStorage.getItem('lotteryCode'); + const phone = localStorage.getItem("lotteryPhone"); + const code = localStorage.getItem("lotteryCode"); if (phone && code) { try { @@ -23,19 +23,19 @@ const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { if (response.errorMessage) { // If authentication fails, redirect to the auth page - router.replace('/lottery/auth'); + router.replace("/lottery/auth"); } else { // ✅ Set the authenticated state setAuth(response, phone, code); setIsLoading(false); } } catch (err) { - console.error('Authentication failed:', err); - router.replace('/lottery/auth'); + console.error("Authentication failed:", err); + router.replace("/lottery/auth"); } } else { // Redirect to the auth page if no credentials are found - router.replace('/lottery/auth'); + router.replace("/lottery/auth"); } };