This commit is contained in:
Kakabay 2025-01-29 18:27:26 +05:00
parent 43bb74c47e
commit 39a9116001
2 changed files with 15 additions and 12 deletions

View File

@ -29,7 +29,6 @@ const LotteryPage = () => {
.then((response) => { .then((response) => {
if (response.errorMessage) { if (response.errorMessage) {
// If authentication fails, redirect to the auth page // If authentication fails, redirect to the auth page
console.log("lotter/", response);
router.replace("/lottery/auth"); router.replace("/lottery/auth");
} else { } else {
// ✅ Set the authenticated state // ✅ Set the authenticated state
@ -44,6 +43,10 @@ const LotteryPage = () => {
} }
}, [setAuth]); }, [setAuth]);
if (!lotteryData?.errorMessage) {
router.replace("/lottery/auth");
}
return ( return (
<ProtectedRoute> <ProtectedRoute>
<div className="flex flex-col md:gap-[128px] gap-[80px] font-roboto md:pt-[64px] sm:pt-[48px] pt-[40px] ms:pb-[128px] pb-[80px] text-lightOnSurface"> <div className="flex flex-col md:gap-[128px] gap-[80px] font-roboto md:pt-[64px] sm:pt-[48px] pt-[40px] ms:pb-[128px] pb-[80px] text-lightOnSurface">

View File

@ -1,9 +1,9 @@
'use client'; "use client";
import { useEffect, useState } from 'react'; import { useEffect, useState } from "react";
import { useRouter } from 'next/navigation'; import { useRouter } from "next/navigation";
import { useLotteryAuth } from '@/store/useLotteryAuth'; import { useLotteryAuth } from "@/store/useLotteryAuth";
import { Queries } from '@/api/queries'; import { Queries } from "@/api/queries";
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
const router = useRouter(); const router = useRouter();
@ -13,8 +13,8 @@ const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
useEffect(() => { useEffect(() => {
const checkAuth = async () => { const checkAuth = async () => {
// ✅ Check credentials from localStorage // ✅ Check credentials from localStorage
const phone = localStorage.getItem('lotteryPhone'); const phone = localStorage.getItem("lotteryPhone");
const code = localStorage.getItem('lotteryCode'); const code = localStorage.getItem("lotteryCode");
if (phone && code) { if (phone && code) {
try { try {
@ -23,19 +23,19 @@ const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
if (response.errorMessage) { if (response.errorMessage) {
// If authentication fails, redirect to the auth page // If authentication fails, redirect to the auth page
router.replace('/lottery/auth'); router.replace("/lottery/auth");
} else { } else {
// ✅ Set the authenticated state // ✅ Set the authenticated state
setAuth(response, phone, code); setAuth(response, phone, code);
setIsLoading(false); setIsLoading(false);
} }
} catch (err) { } catch (err) {
console.error('Authentication failed:', err); console.error("Authentication failed:", err);
router.replace('/lottery/auth'); router.replace("/lottery/auth");
} }
} else { } else {
// Redirect to the auth page if no credentials are found // Redirect to the auth page if no credentials are found
router.replace('/lottery/auth'); router.replace("/lottery/auth");
} }
}; };