diff --git a/components/TrialWarning.tsx b/components/TrialWarning.tsx index d3e94b4..450372e 100644 --- a/components/TrialWarning.tsx +++ b/components/TrialWarning.tsx @@ -2,9 +2,11 @@ import React, { useState } from "react"; import { useSecureTrial } from "../hooks/useSecureTrial"; +import { useAuth } from "../contexts/AuthContext"; import { AuthModal } from "./AuthModal"; export const TrialWarning: React.FC = () => { + const { isAuthenticated } = useAuth(); const { trialExpired, timeRemaining, @@ -40,7 +42,13 @@ export const TrialWarning: React.FC = () => { ); } - if (!isInTrial && !trialExpired && !trialBlocked) return null; + // Don't show anything while loading, if user is authenticated, or if no trial state + if ( + isLoading || + isAuthenticated || + (!isInTrial && !trialExpired && !trialBlocked) + ) + return null; return ( <> diff --git a/hooks/useSecureTrial.tsx b/hooks/useSecureTrial.tsx index ce6464c..e6f89cf 100644 --- a/hooks/useSecureTrial.tsx +++ b/hooks/useSecureTrial.tsx @@ -24,7 +24,7 @@ interface TrialRecord { } export const useSecureTrial = () => { - const { isAuthenticated } = useAuth(); + const { isAuthenticated, isLoading: authLoading } = useAuth(); const [trialStartTime, setTrialStartTime] = useState(null); const [trialExpired, setTrialExpired] = useState(false); const [timeRemaining, setTimeRemaining] = useState(TRIAL_DURATION_MS); @@ -329,6 +329,11 @@ export const useSecureTrial = () => { useEffect(() => { const initializeTrial = async () => { + // Wait for auth to finish loading before initializing trial + if (authLoading) { + return; + } + setIsLoading(true); // If user is authenticated, no trial needed @@ -424,7 +429,7 @@ export const useSecureTrial = () => { }; initializeTrial(); - }, [isAuthenticated]); + }, [isAuthenticated, authLoading]); // Update timer every second useEffect(() => { @@ -475,6 +480,6 @@ export const useSecureTrial = () => { isInTrial, isAccessBlocked, trialBlocked, - isLoading, + isLoading: isLoading || authLoading, }; }; diff --git a/package-lock.json b/package-lock.json index b8ba063..83b446a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "practice-exams-platform", - "version": "1.4.1", + "version": "1.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "practice-exams-platform", - "version": "1.4.1", + "version": "1.4.2", "dependencies": { "@apollo/client": "^3.7.9", "@apollo/server": "^4.11.0", diff --git a/package.json b/package.json index 783df76..ae95aee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "practice-exams-platform", - "version": "1.4.1", + "version": "1.4.2", "private": true, "engines": { "node": "20.x"