aboutsummaryrefslogtreecommitdiffstats
path: root/panel/src/contexts
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-31 12:16:49 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-31 12:16:49 +0530
commit7dfbe0f363a434cfda5f9be996d194f03c36879c (patch)
treeae687ee38c31106807934fca524811eb45da0ec9 /panel/src/contexts
downloadadmin-panel-7dfbe0f363a434cfda5f9be996d194f03c36879c.tar.gz
admin-panel-7dfbe0f363a434cfda5f9be996d194f03c36879c.tar.bz2
admin-panel-7dfbe0f363a434cfda5f9be996d194f03c36879c.zip
new project
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>;
+};