diff --git a/src/App.jsx b/src/App.jsx
index a6212b3..5e654be 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -2,7 +2,7 @@ import { useEffect, useState, Suspense, lazy } from 'react';
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
-import { auth } from './service/firebase';
+import { auth , getUserSubscription } from './service/firebase';
import styles from './App.module.scss';
import Loading from './pages/Loading/loading';
import Pricing from './pages/Payement/Pricing/Pricing';
@@ -21,6 +21,7 @@ const App = () => {
const [user, setUser] = useState(() => JSON.parse(localStorage.getItem('user')) || null);
const [loading, setLoading] = useState(true);
const [showLoading, setShowLoading] = useState(false);
+ const [subscription, setSubscription] = useState(0);
useEffect(() => {
const timeoutId = setTimeout(() => setShowLoading(true), 6000);
@@ -28,10 +29,11 @@ const App = () => {
const unsubscribe = auth.onAuthStateChanged((user) => {
if (user) {
localStorage.setItem('user', JSON.stringify(user));
+ setUser(user);
} else {
localStorage.removeItem('user');
+ setUser(null);
}
- setUser(user);
setLoading(false);
clearTimeout(timeoutId);
});
@@ -42,6 +44,20 @@ const App = () => {
};
}, []);
+ useEffect(() => {
+ if (user) {
+ const fetchSubscription = async () => {
+ try {
+ const userSubscription = await getUserSubscription(user.uid);
+ setSubscription(userSubscription || 0);
+ } catch (error) {
+ console.error('Error fetching subscription:', error);
+ }
+ };
+ fetchSubscription();
+ }
+ }, [user]);
+
if (loading && showLoading) {
return