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 () => { {/* */} - */} + -
+ {/*
or login with
@@ -98,7 +136,8 @@ export default () => { -
+
*/} +
diff --git a/src/pages/dashboard/DashboardOverview.js b/src/pages/dashboard/DashboardOverview.js index 77fe27d9..9c4b4e96 100644 --- a/src/pages/dashboard/DashboardOverview.js +++ b/src/pages/dashboard/DashboardOverview.js @@ -32,138 +32,159 @@ import { import { PageVisitsTable } from "../../components/Tables"; import { trafficShares, totalOrders } from "../../data/charts"; +import { getAuth, onAuthStateChanged } from "firebase/auth"; + export default () => { + var loadPage = false; + const auth = getAuth(); + 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"); + loadPage = true; + // ... + } else { + // User is signed out + // ... + } + }); + + return ( + // {loadPage === true && <>} <> -
- - +
+ + + + - - - - something Task - - - - New Task - - - {" "} - Upload Files - - - Preview - Security - - - - - {/* - Upgrade to Pro - */} - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ); + + something Task +
+ + + New Task + + + {" "} + Upload Files + + + Preview + Security + + + + + {/* + Upgrade to Pro + */} + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ) + };