Various repairs to broken signup button not submitting data

This commit is contained in:
Ray 2023-09-18 14:09:45 +00:00 committed by GitHub
parent d65f8e720f
commit 3f05cd8dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 36 deletions

View File

@ -14,7 +14,7 @@ import { Signup } from "./pages/Signup"
function App() { function App() {
const FBapp = initializeApp(FirebaseConfig) const FBapp = initializeApp(FirebaseConfig)
const FBauth = getAuth(FBapp) const FBauth = getAuth()
// navigation array // navigation array
const navItems = [ const navItems = [
{ label: "Home", link: "/" }, { label: "Home", link: "/" },
@ -42,11 +42,13 @@ function App() {
// signing up a user // signing up a user
const signUp = (email, password) => { const signUp = (email, password) => {
createUserWithEmailAndPassword(FBauth, email, password) createUserWithEmailAndPassword(FBauth, email, password)
.then((userCredential) => { .then( (userCredential) => {
// do something // do something
}) })
.catch((error) => console.log(error.message)) .catch((error) => console.log(error.message))
} }
return ( return (
<div className="App"> <div className="App">
<Header items={nav} /> <Header items={nav} />
@ -54,7 +56,7 @@ function App() {
<Route path="/" element={<Home greeting="Hey you're at home!" />} /> <Route path="/" element={<Home greeting="Hey you're at home!" />} />
<Route path="/about" element={<About greeting="Hey you, this is about page!" handler={saySomething} />} /> <Route path="/about" element={<About greeting="Hey you, this is about page!" handler={saySomething} />} />
<Route path="/contact" element={<Contact greeting="Hey you, this is contact page!" />} /> <Route path="/contact" element={<Contact greeting="Hey you, this is contact page!" />} />
<Route path="/signup" element={<Signup handler={signUp}/>} /> <Route path="/signup" element={ <Signup handler={signUp}/> } />
</Routes> </Routes>
</div> </div>
); );

View File

@ -10,15 +10,16 @@ export function Signup ( props ) {
const[validusername,setValidusername] = useState(false) const[validusername,setValidusername] = useState(false)
const[useremail,setUseremail] = useState('') const[useremail,setUseremail] = useState('')
const[validemail,setValidemail] = useState(false) const[validemail,setValidemail] = useState(false)
const[password,setUserpassword] = useState('') const[userpassword,setUserpassword] = useState('')
const[validpassword,setValidpassword] = useState(false) const[validpassword,setValidpassword] = useState(false)
const submitHandler = (evt) => { const submitHandler = (evt) => {
evt.preventDefault() evt.preventDefault()
props.handler(useremail, password) props.handler( useremail, userpassword )
} }
useEffect( () => { useEffect( () => {
if(username.length >= 4) { if( username.length >= 4 ) {
setValidusername(true) setValidusername(true)
} }
else { else {
@ -27,29 +28,29 @@ export function Signup ( props ) {
}, [username] ) }, [username] )
useEffect( () => { useEffect( () => {
if(useremail.indexOf('@') > 0 ) { if( useremail.indexOf('@') > 0 ) {
setValidemail(true) setValidemail(true)
} }
else { else {
setValidemail(false) setValidemail(false)
} }
}, [useremail] ) }, [useremail])
useEffect( () => { useEffect( () => {
if( password.length >= 8 ) { if( userpassword.length >= 8 ) {
setValidpassword(true) setValidpassword(true)
} }
else{ else{
setValidpassword(false) setValidpassword(false)
} }
}, [password] ) }, [userpassword])
return ( return (
<Container> <Container>
<Row> <Row>
<Col md={{span: 4, offset:4}}> <Col md={{span: 4, offset:4}}>
<Form> <Form onSubmit={submitHandler}>
<Form.Group> <Form.Group>
<Form.Label>Username</Form.Label> <Form.Label>Username</Form.Label>
<Form.Control <Form.Control