Add Signup state to reflect userState
This commit is contained in:
parent
ddf07b62c5
commit
02d06b2385
19
src/App.js
19
src/App.js
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue