diff --git a/src/components/Navbar.js b/src/components/Navbar.js
index 348b92c6..bac9435c 100644
--- a/src/components/Navbar.js
+++ b/src/components/Navbar.js
@@ -12,11 +12,49 @@ import { HashLink } from 'react-router-hash-link';
import NOTIFICATIONS_DATA from "../data/notifications";
import Profile3 from "../assets/img/team/profile-picture-3.jpg";
+//auth imports
+import { getAuth, onAuthStateChanged } from "firebase/auth";
+import { collection, query, where,getDocs } from "firebase/firestore";
+import db from '../firebase.config';
export default (props) => {
const [notifications, setNotifications] = useState(NOTIFICATIONS_DATA);
const areNotificationsRead = notifications.reduce((acc, notif) => acc && notif.read, true);
+ var loadPage = false;
+
+ const auth = getAuth();
+ var userName = "";
+ onAuthStateChanged(auth, (user) => {
+ if (user) {
+ // User is signed in, see docs for a list of available properties
+ // https://firebase.google.com/docs/reference/js/firebase.User
+ const uid = user.uid;
+ console.log(uid, "loadPage now true in navbar");
+ loadPage = true;
+ // var doc = fetchUser(uid)
+ fetchUser(uid)
+ console.log(userName)
+ // ...
+ } else {
+ // User is signed out
+ // ...
+ }
+ });
+
+ const fetchUser=async(uid)=>{
+ const q = query(collection(db, "users"), where("uid", "==", uid));
+ const querySnapshot = await getDocs(q);
+ console.log(querySnapshot)
+ querySnapshot.forEach((doc) => {
+ // doc.data() is never undefined for query doc snapshots
+ console.log(doc.id, " => ", doc.data().username);
+ userName = doc.data().username
+ console.log(userName)
+ document.getElementById("username_display").innerHTML = userName
+ });
+ }
+
const markNotificationsAsRead = () => {
setTimeout(() => {
setNotifications(notifications.map(n => ({ ...n, read: true })));
@@ -92,7 +130,7 @@ export default (props) => {
- Bonnie Green
+ {userName}
diff --git a/src/pages/Mobile/Signin.js b/src/pages/Mobile/Signin.js
index cd790689..13973547 100644
--- a/src/pages/Mobile/Signin.js
+++ b/src/pages/Mobile/Signin.js
@@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft, faEnvelope, faUnlockAlt } from "@fortawesome/free-solid-svg-icons";
import { faFacebookF, faGithub, faTwitter } from "@fortawesome/free-brands-svg-icons";
import { Col, Row, Form, Card, Button, FormCheck, Container, InputGroup } from 'react-bootstrap';
-import { Link } from 'react-router-dom';
+import { useHistory, Link } from 'react-router-dom';
import { Routes } from "../../routes";
import BgImage from "../../assets/img/illustrations/signin.svg";
@@ -12,17 +12,23 @@ import db from '../../firebase.config';
import { doc, onSnapshot, collection, query, where,getDocs } from "firebase/firestore";
import {useState,useEffect} from 'react';
+import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
-
-
+const initialFormData = Object.freeze({
+ password: "",
+ email: ""
+});
export default () => {
+ const auth = getAuth();
const q = query(collection(db, "users"));
-
+ const [formData, updateFormData] = useState(initialFormData);
+ const history = useHistory();
const [users,setUsers]=useState([])
+
useEffect(() => {
- fetchUsers();
+ // fetchUsers();
}, [])
const fetchUsers=async()=>{
const querySnapshot = await getDocs(q);
@@ -34,6 +40,35 @@ export default () => {
}
+ const handleChange = (e) => {
+ console.log("handleChange called")
+ updateFormData({
+ ...formData,
+
+ // Trimming any whitespace
+ [e.target.name]: e.target.value.trim()
+ });
+
+ };
+ const logInWithEmailAndPassword = async () => {
+ var res = null
+ // console.log(formData)
+ try {
+ const email = String(formData.email)
+ const password = String(formData.password)
+ console.log(email, password)
+ res = await signInWithEmailAndPassword(auth, email, password);
+ } catch (err) {
+ console.error(err);
+ alert(err.message);
+ }
+ finally {
+ const user = res.user;
+ console.log(user)
+ history.push("/dashboard/overview");
+ }
+ };
+
return (
@@ -56,7 +91,7 @@ export default () => {
-
+
@@ -66,7 +101,7 @@ export default () => {
-
+
@@ -80,12 +115,15 @@ export default () => {
{/*
*/}
-