這是我的代碼,但找不到任何解決方案,資料已上傳到 firebase ,并且身份驗證處理了我的電子郵件 ID 和詳細資訊,但是,在嘗試登錄時它顯示錯誤,我找不到任何解決方案,嘗試使用 trim() 函式,但沒用。所以請嘗試幫助
我的代碼
import React ,{useState,useContext}from 'react';
import FirebaseContext from '../../store/FirebaseContext.js'
import './Login.css';
import {useHistory} from "react-router-dom"
[![Screen Shot for the error message][1]][1]
function Login() {
const history=useHistory()
const [password,setPassword]=useState('')
const [email,setEmail]=useState('')
const {firebase}=useContext(FirebaseContext)
const handleLogin=(e)=>{
e.preventDefault()
firebase.auth().signInWithEmailAndPassword(email.trim(),password)
.then(()=>{
alert('LoggedIn')
history.push("/")
})
.catch((error)=>{
alert(error.message)
})
}
return (
<div className='backdrop'>
<div className="loginParentDiv">
<img className='login-logo' src="https://t4.ftcdn.net/jpg/03/77/48/55/360_F_377485593_QHN6cjoNsNdOBoJNOwVRlFcHyZ0M9n3P.jpg"></img>
<br />
<form onSubmit={handleLogin}>
<label htmlFor="fname">Email</label>
<br />
<br />
<input
className="input"
type="email"
name="email"
placeholder='[email protected]'
/>
<br />
<br />
<label htmlFor="lname">Password</label>
<br />
<br />
<input
className="input"
type="password"
id="lname"
name="password"
placeholder=''
/>
<br />
<br />
<button>Login</button>
</form>
<a href='/signup'>Signup</a>
</div>
</div>
);
}
export default Login;
我的代碼
uj5u.com熱心網友回復:
您的輸入中沒有onChange方法。首先使用 console.log 檢查您是否收到了您所在州的電子郵件。
嘗試這個
<input
className="input"
type="email"
onChange={(e) => setEmail(e.target.value)}
name="email"
placeholder='[email protected]'
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/498225.html
