From 710f559721975112c26f1be81636c9f25ccf9625 Mon Sep 17 00:00:00 2001 From: abdel mouzahir Date: Tue, 2 Jul 2024 12:02:39 -0600 Subject: [PATCH] trying to show username in saitstaff --- Components/UserGreeting.js | 15 +++++++++++++++ app/sait-staff/login/page.js | 11 +++++------ app/sait-staff/page.js | 11 ++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 Components/UserGreeting.js diff --git a/Components/UserGreeting.js b/Components/UserGreeting.js new file mode 100644 index 0000000..a13f9e3 --- /dev/null +++ b/Components/UserGreeting.js @@ -0,0 +1,15 @@ +'use client' +// components/UserGreeting.js + +const UserGreeting = () => { + const userDisplayName = sessionStorage.getItem("displayName") || "User"; + + return ( +

+ Hi! {userDisplayName} +

+ ); + }; + + export default UserGreeting; + \ No newline at end of file diff --git a/app/sait-staff/login/page.js b/app/sait-staff/login/page.js index 52a092f..4e25539 100644 --- a/app/sait-staff/login/page.js +++ b/app/sait-staff/login/page.js @@ -5,10 +5,10 @@ import { auth } from "@/app/firebase/config"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { sendPasswordResetEmail } from "firebase/auth"; -import Modal from "@/Components/Modal"; +import Modal from "@/components/Modal"; import { BiSolidCommentError } from "react-icons/bi"; -const sign_in = () => { +const SignIn = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loginError, setLoginError] = useState(""); @@ -22,6 +22,7 @@ const sign_in = () => { .then((userCredential) => { const user = userCredential.user; sessionStorage.setItem("user", true); + sessionStorage.setItem("displayName", user.displayName || "User"); router.push("/sait-staff"); setEmail(""); setPassword(""); @@ -64,8 +65,7 @@ const sign_in = () => { backgroundSize: "cover", // Adjusts the size of the background image backgroundPosition: "center", // Centers the background image backgroundRepeat: "no-repeat", // Prevents the background image from repeating - - }} + }} >
@@ -116,7 +116,6 @@ const sign_in = () => { Sign In
- @@ -162,4 +161,4 @@ const sign_in = () => { ); }; -export default sign_in; \ No newline at end of file +export default SignIn; diff --git a/app/sait-staff/page.js b/app/sait-staff/page.js index 9cde790..aa6a073 100644 --- a/app/sait-staff/page.js +++ b/app/sait-staff/page.js @@ -6,17 +6,21 @@ import Dash from "./overviewDash"; import Settings from "./settingS"; import { AiOutlineUser } from "react-icons/ai"; import { LuLogOut } from "react-icons/lu"; -import { useUserAuth } from "@/services/utils"; +import { onAuthStateChanged } from 'firebase/auth'; +import { auth } from '@/app/firebase/config'; +import UserGreeting from '@/components/UserGreeting'; //import navbar import SaitStaffNav from "@/components/SaitStaffNav"; import { CgProfile } from "react-icons/cg"; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useRouter } from "next/navigation"; export default function Page() { const [isCollapsed, setIsCollapsed] = useState(false); const [activeTab, setActiveTab] = useState('home'); // Set default active tab + const [user, setUser] = useState(null); + const router = useRouter(); // function to select the tab @@ -29,6 +33,7 @@ export default function Page() { return router.push("/"); } + return (
-

Hi! {"User"}

+