Add Signup state to reflect userState

This commit is contained in:
Ray 2023-09-19 08:57:07 +00:00 committed by GitHub
parent ddf07b62c5
commit 02d06b2385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import { FirebaseConfig } from "./config/Config"
import { initializeApp } from "firebase/app" import { initializeApp } from "firebase/app"
import { Routes, Route } from "react-router-dom" import { Routes, Route } from "react-router-dom"
import { useState } from "react" import { useState } from "react"
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; import { getAuth, createUserWithEmailAndPassword, onAuthStateChanged } from "firebase/auth";
import { Header } from "./components/Header" import { Header } from "./components/Header"
import './App.css' import './App.css'
@ -15,6 +15,8 @@ import { Signup } from "./pages/Signup"
function App() { function App() {
const FBapp = initializeApp(FirebaseConfig) const FBapp = initializeApp(FirebaseConfig)
const FBauth = getAuth() const FBauth = getAuth()
const [auth, setAuth] = useState(false)
// navigation array // navigation array
const navItems = [ const navItems = [
{ label: "Home", link: "/" }, { label: "Home", link: "/" },
@ -34,6 +36,21 @@ function App() {
/// application states /// application states
const [nav, setNav] = useState(navItems) 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) => { const saySomething = (word) => {
alert(word) alert(word)