diff --git a/WebApp/src/components/navbar/navbar.scss b/WebApp/src/components/navbar/navbar.scss
index 9473ab0..921ab9e 100644
--- a/WebApp/src/components/navbar/navbar.scss
+++ b/WebApp/src/components/navbar/navbar.scss
@@ -1,5 +1,4 @@
.navbar {
- width: 100vw;
min-height: 100px;
//border-bottom: 0.5px solid rgb(231, 228, 228);
display: flex;
@@ -34,6 +33,7 @@
.icon {
font-size: 50px;
color: white;
+ cursor: pointer;
}
}
}
diff --git a/WebApp/src/context/AuthContext.js b/WebApp/src/context/AuthContext.js
new file mode 100644
index 0000000..def028e
--- /dev/null
+++ b/WebApp/src/context/AuthContext.js
@@ -0,0 +1,22 @@
+import { createContext, useEffect, useReducer } from "react";
+import AuthReducer from "./AuthReducer";
+
+const INITIAL_STATE = {
+ currentUser: JSON.parse(localStorage.getItem("user")) || null,
+};
+
+export const AuthContext = createContext(INITIAL_STATE);
+
+export const AuthContextProvider = ({ children }) => {
+ const [state, dispatch] = useReducer(AuthReducer, INITIAL_STATE);
+
+ useEffect(() => {
+ localStorage.setItem("user", JSON.stringify(state.currentUser));
+ }, [state.currentUser]);
+
+ return (
+
+ {children}
+
+ );
+};
diff --git a/WebApp/src/context/AuthReducer.js b/WebApp/src/context/AuthReducer.js
new file mode 100644
index 0000000..24aaee7
--- /dev/null
+++ b/WebApp/src/context/AuthReducer.js
@@ -0,0 +1,18 @@
+const AuthReducer = (state, action) => {
+ switch (action.type) {
+ case "LOGIN": {
+ return {
+ currentUser: action.payload,
+ };
+ }
+ case "LOGOUT": {
+ return {
+ currentUser: null,
+ };
+ }
+ default:
+ return state;
+ }
+};
+
+export default AuthReducer;
diff --git a/WebApp/src/index.js b/WebApp/src/index.js
index 6e04ccb..a516aa1 100644
--- a/WebApp/src/index.js
+++ b/WebApp/src/index.js
@@ -1,8 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
+import { AuthContextProvider } from "./context/AuthContext";
ReactDOM.render(
-
,
+
+
+ ,
document.getElementById("root")
);
diff --git a/WebApp/src/pages/home/home.scss b/WebApp/src/pages/home/home.scss
index 71d7d1a..64c2a27 100644
--- a/WebApp/src/pages/home/home.scss
+++ b/WebApp/src/pages/home/home.scss
@@ -3,7 +3,6 @@
display: flex;
flex-direction: column;
height: 100vh;
- width: 100vw;
//overflow: hidden;
.main
diff --git a/WebApp/src/pages/login/Login.jsx b/WebApp/src/pages/login/Login.jsx
index 394f084..3ff7a6c 100644
--- a/WebApp/src/pages/login/Login.jsx
+++ b/WebApp/src/pages/login/Login.jsx
@@ -1,8 +1,9 @@
-import { useState } from "react";
+import { useContext, useState } from "react";
import "./login.scss";
import { signInWithEmailAndPassword } from "firebase/auth";
import { auth } from "../../firebase";
import { useNavigate } from "react-router-dom";
+import { AuthContext } from "../../context/AuthContext"
const Login = () => {
const [error, setError] = useState(false);
@@ -11,6 +12,8 @@ const Login = () => {
const navigate = useNavigate();
+ const {dispatch} = useContext(AuthContext)
+
const handleLogin = (e) => {
e.preventDefault();
@@ -18,6 +21,7 @@ const Login = () => {
.then((userCredential) => {
// Signed in
const user = userCredential.user;
+ dispatch({type:"LOGIN", payload:user})
navigate("/");
})
.catch((error) => {