From 02d06b23855d8739ee44bbd5a14313fcacdb0e47 Mon Sep 17 00:00:00 2001 From: "Rayyan (Rayy)" Date: Tue, 19 Sep 2023 08:57:07 +0000 Subject: [PATCH] Add Signup state to reflect userState --- src/App.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 307c14a..f4f647b 100644 --- a/src/App.js +++ b/src/App.js @@ -2,7 +2,7 @@ import { FirebaseConfig } from "./config/Config" import { initializeApp } from "firebase/app" import { Routes, Route } from "react-router-dom" import { useState } from "react" -import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; +import { getAuth, createUserWithEmailAndPassword, onAuthStateChanged } from "firebase/auth"; import { Header } from "./components/Header" import './App.css' @@ -15,6 +15,8 @@ import { Signup } from "./pages/Signup" function App() { const FBapp = initializeApp(FirebaseConfig) const FBauth = getAuth() + const [auth, setAuth] = useState(false) + // navigation array const navItems = [ { label: "Home", link: "/" }, @@ -34,6 +36,21 @@ function App() { /// application states const [nav, setNav] = useState(navItems) + // authentication observer + onAuthStateChanged(FBauth, (user) => { + if( user ) { + // currently authenticated + setAuth( user ) + setNav( AuthnavItems ) + + } + else { + // currently unauthenticated + setAuth( false ) + setNav( navItems ) + } + }) + const saySomething = (word) => { alert(word)