Javascript firebase身份验证错误:电子邮件地址格式错误
我在连接Firebase时遇到问题 此错误“错误:电子邮件地址格式不正确。” 总是跳跃。 我设置了.trim()函数 我把输入的类型改为3种不同的类型 最奇怪的是,每次更改只起一次作用。 之后,消息再次弹出Javascript firebase身份验证错误:电子邮件地址格式错误,javascript,reactjs,firebase,authentication,Javascript,Reactjs,Firebase,Authentication,我在连接Firebase时遇到问题 此错误“错误:电子邮件地址格式不正确。” 总是跳跃。 我设置了.trim()函数 我把输入的类型改为3种不同的类型 最奇怪的是,每次更改只起一次作用。 之后,消息再次弹出 import {Redirect, useHistory} from "react-router-dom" import app from "./../../firebase" import {AuthContext} from "./../
import {Redirect, useHistory} from "react-router-dom"
import app from "./../../firebase"
import {AuthContext} from "./../../Auth"
export default function Login(props) {
const history = useHistory();
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const handleLogin = useCallback(
async event => {
event.preventDefault()
try {
await app
.auth()
.signInWithEmailAndPassword(email.trim(),password)
history.push("/")
} catch (error) {
alert(error)
}
},[]
)
const {currentUser} = useContext(AuthContext)
if(currentUser){
console.log(email)
return <Redirect to={'/'}/>
}
return (
<div>
<h1>Login</h1>
<form onSubmit={handleLogin}>
<label>
Email
<input onChange={(e)=>{setEmail(e.target.value)}} name='name' type='textEmailSubject' placeholder='Email'/>
</label>
<label>
Password
<input onChange={(e)=>{setPassword(e.target.value)}} name='name' type='password' placeholder='Password'/>
</label>
<button type='submit'>Log in</button>
</form>
</div>
)
}
从“react router dom”导入{Redirect,useHistory}
从“/./../firebase”导入应用程序
从“/./../Auth”导入{AuthContext}
导出默认功能登录(道具){
const history=useHistory();
const[email,setEmail]=useState(“”)
const[password,setPassword]=useState(“”)
const handleLogin=useCallback(
异步事件=>{
event.preventDefault()
试一试{
等待应用程序
.auth()
.signInWithEmailAndPassword(email.trim(),password)
历史记录。推送(“/”)
}捕获(错误){
警报(错误)
}
},[]
)
const{currentUser}=useContext(AuthContext)
如果(当前用户){
控制台日志(电子邮件)
返回
}
返回(
登录
电子邮件
{setEmail(e.target.value)}name='name'type='textmailsubject'占位符='Email'/>
密码
{setPassword(e.target.value)}name='name'type='password'占位符='password'/>
登录
)
}