test
This commit is contained in:
parent
43bb74c47e
commit
39a9116001
|
|
@ -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 (
|
||||
<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">
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue