Skip to content

Commit 4521a37

Browse files
Merge pull request #73 from Ditectrev/feature/fix-trial-reload-and-login
Feature/fix trial reload and login
2 parents 252d11c + d019801 commit 4521a37

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
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
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "practice-exams-platform",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"private": true,
55
"engines": {
66
"node": "20.x"

0 commit comments

Comments
 (0)