aboutsummaryrefslogtreecommitdiffstats
path: root/panel/src/contexts
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-08-01 17:35:27 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-08-01 17:35:27 +0530
commitfb04271b5288e8fb5891b7d6326f4806d12b82d5 (patch)
treee459c3e1f8bb6e168becdddd0d48779135d91a7f /panel/src/contexts
parent4bb13ee84f6bb51cba6544ccd0690ab2049512a9 (diff)
parentb3c07fd9f1664dda4f16357aaca74dff8226401d (diff)
downloadadmin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.tar.gz
admin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.tar.bz2
admin-panel-fb04271b5288e8fb5891b7d6326f4806d12b82d5.zip
Merge remote-tracking branch 'project/master'
Diffstat (limited to 'panel/src/contexts')
-rw-r--r--panel/src/contexts/AuthContext.jsx27
1 files changed, 27 insertions, 0 deletions
diff --git a/panel/src/contexts/AuthContext.jsx b/panel/src/contexts/AuthContext.jsx
new file mode 100644
index 0000000..cf8c7b5
--- /dev/null
+++ b/panel/src/contexts/AuthContext.jsx
@@ -0,0 +1,27 @@
+import React, { createContext, useContext, useEffect, useState } from 'react';
+import { auth } from '../firebase';
+import { onAuthStateChanged } from 'firebase/auth';
+
+const AuthContext = createContext();
+
+export const useAuth = () => {
+ return useContext(AuthContext);
+};
+
+export const AuthProvider = ({ children }) => {
+ const [currentUser, setCurrentUser] = useState(null);
+
+ useEffect(() => {
+ const unsubscribe = onAuthStateChanged(auth, (user) => {
+ setCurrentUser(user);
+ });
+
+ return unsubscribe;
+ }, []);
+
+ const value = {
+ currentUser,
+ };
+
+ return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
+};