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 2
2
3
3
import React , { useState } from "react" ;
4
4
import { useSecureTrial } from "../hooks/useSecureTrial" ;
5
+ import { useAuth } from "../contexts/AuthContext" ;
5
6
import { AuthModal } from "./AuthModal" ;
6
7
7
8
export const TrialWarning : React . FC = ( ) => {
9
+ const { isAuthenticated } = useAuth ( ) ;
8
10
const {
9
11
trialExpired,
10
12
timeRemaining,
@@ -40,7 +42,13 @@ export const TrialWarning: React.FC = () => {
40
42
) ;
41
43
}
42
44
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 ;
44
52
45
53
return (
46
54
< >
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ interface TrialRecord {
24
24
}
25
25
26
26
export const useSecureTrial = ( ) => {
27
- const { isAuthenticated } = useAuth ( ) ;
27
+ const { isAuthenticated, isLoading : authLoading } = useAuth ( ) ;
28
28
const [ trialStartTime , setTrialStartTime ] = useState < number | null > ( null ) ;
29
29
const [ trialExpired , setTrialExpired ] = useState ( false ) ;
30
30
const [ timeRemaining , setTimeRemaining ] = useState < number > ( TRIAL_DURATION_MS ) ;
@@ -329,6 +329,11 @@ export const useSecureTrial = () => {
329
329
330
330
useEffect ( ( ) => {
331
331
const initializeTrial = async ( ) => {
332
+ // Wait for auth to finish loading before initializing trial
333
+ if ( authLoading ) {
334
+ return ;
335
+ }
336
+
332
337
setIsLoading ( true ) ;
333
338
334
339
// If user is authenticated, no trial needed
@@ -424,7 +429,7 @@ export const useSecureTrial = () => {
424
429
} ;
425
430
426
431
initializeTrial ( ) ;
427
- } , [ isAuthenticated ] ) ;
432
+ } , [ isAuthenticated , authLoading ] ) ;
428
433
429
434
// Update timer every second
430
435
useEffect ( ( ) => {
@@ -475,6 +480,6 @@ export const useSecureTrial = () => {
475
480
isInTrial,
476
481
isAccessBlocked,
477
482
trialBlocked,
478
- isLoading,
483
+ isLoading : isLoading || authLoading ,
479
484
} ;
480
485
} ;
You can’t perform that action at this time.
0 commit comments