File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 22
33import React , { useState } from "react" ;
44import { useSecureTrial } from "../hooks/useSecureTrial" ;
5+ import { useAuth } from "../contexts/AuthContext" ;
56import { AuthModal } from "./AuthModal" ;
67
78export const TrialWarning : React . FC = ( ) => {
9+ const { isAuthenticated } = useAuth ( ) ;
810 const {
911 trialExpired,
1012 timeRemaining,
@@ -40,7 +42,13 @@ export const TrialWarning: React.FC = () => {
4042 ) ;
4143 }
4244
43- if ( ! isInTrial && ! trialExpired && ! trialBlocked ) return null ;
45+ // Don't show anything while loading, if user is authenticated, or if no trial state
46+ if (
47+ isLoading ||
48+ isAuthenticated ||
49+ ( ! isInTrial && ! trialExpired && ! trialBlocked )
50+ )
51+ return null ;
4452
4553 return (
4654 < >
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ interface TrialRecord {
2424}
2525
2626export const useSecureTrial = ( ) => {
27- const { isAuthenticated } = useAuth ( ) ;
27+ const { isAuthenticated, isLoading : authLoading } = useAuth ( ) ;
2828 const [ trialStartTime , setTrialStartTime ] = useState < number | null > ( null ) ;
2929 const [ trialExpired , setTrialExpired ] = useState ( false ) ;
3030 const [ timeRemaining , setTimeRemaining ] = useState < number > ( TRIAL_DURATION_MS ) ;
@@ -329,6 +329,11 @@ export const useSecureTrial = () => {
329329
330330 useEffect ( ( ) => {
331331 const initializeTrial = async ( ) => {
332+ // Wait for auth to finish loading before initializing trial
333+ if ( authLoading ) {
334+ return ;
335+ }
336+
332337 setIsLoading ( true ) ;
333338
334339 // If user is authenticated, no trial needed
@@ -424,7 +429,7 @@ export const useSecureTrial = () => {
424429 } ;
425430
426431 initializeTrial ( ) ;
427- } , [ isAuthenticated ] ) ;
432+ } , [ isAuthenticated , authLoading ] ) ;
428433
429434 // Update timer every second
430435 useEffect ( ( ) => {
@@ -475,6 +480,6 @@ export const useSecureTrial = () => {
475480 isInTrial,
476481 isAccessBlocked,
477482 trialBlocked,
478- isLoading,
483+ isLoading : isLoading || authLoading ,
479484 } ;
480485} ;
You can’t perform that action at this time.
0 commit comments