many fixes

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-06 14:31:42 +00:00
parent 4a16a6a402
commit c455a5ad83
21 changed files with 1497 additions and 242 deletions

View File

@@ -4,8 +4,6 @@ import { useAuthStore } from "../../store/authStore";
import { useErrorHandler } from "../../hooks/useErrorHandler";
import { trackLoading } from "../common/LoadingStateMonitor";
const PRICING_URL = "https://igny8.com/pricing";
interface ProtectedRouteProps {
children: ReactNode;
}
@@ -21,6 +19,20 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
const [showError, setShowError] = useState(false);
const [errorMessage, setErrorMessage] = useState<string>('');
const PLAN_ALLOWED_PATHS = [
'/account/plans',
'/account/billing',
'/account/purchase-credits',
'/account/settings',
'/account/team',
'/account/usage',
'/billing',
];
const isPlanAllowedPath = PLAN_ALLOWED_PATHS.some((prefix) =>
location.pathname.startsWith(prefix)
);
// Track loading state
useEffect(() => {
trackLoading('auth-loading', loading);
@@ -37,11 +49,6 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
logout();
return;
}
if (!user.account.plan) {
logout();
window.location.href = PRICING_URL;
}
}, [isAuthenticated, user, logout]);
// Immediate check on mount: if loading is true, reset it immediately
@@ -111,6 +118,11 @@ export default function ProtectedRoute({ children }: ProtectedRouteProps) {
return <Navigate to="/signin" state={{ from: location }} replace />;
}
// If authenticated but missing an active plan, keep user inside billing/onboarding
if (user?.account && !user.account.plan && !isPlanAllowedPath) {
return <Navigate to="/account/plans" state={{ from: location }} replace />;
}
return <>{children}</>;
}

View File

@@ -51,8 +51,8 @@ export default function SignUpForm() {
last_name: formData.lastName,
});
// Redirect to home after successful registration
navigate("/", { replace: true });
// Redirect to plan selection after successful registration
navigate("/account/plans", { replace: true });
} catch (err: any) {
setError(err.message || "Registration failed. Please try again.");
}