Skip to content

Commit 3253691

Browse files
Merge branch 'main' into feature/header-elements
2 parents 6ceec6f + 4521a37 commit 3253691

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

components/TrialWarning.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import React, { useState } from "react";
44
import { useSecureTrial } from "../hooks/useSecureTrial";
5+
import { useAuth } from "../contexts/AuthContext";
56
import { AuthModal } from "./AuthModal";
67

78
export 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
<>

hooks/useSecureTrial.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface TrialRecord {
2424
}
2525

2626
export 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
};

0 commit comments

Comments
 (0)