Node.js 使用电子邮件重定向&;Firebase身份验证节点中的密码

Node.js 使用电子邮件重定向&;Firebase身份验证节点中的密码,node.js,firebase,firebase-authentication,Node.js,Firebase,Firebase Authentication,我想使用此电子邮件登录admin@gmail.com已在我的Firebase身份验证中注册 因此,我写了登录认证,将登录,如果电子邮件和密码由firebase认证满意 const handleLogin = (e) => { e.preventDefault(); fire.auth() .signInWithEmailAndPassword(email, password) .then(() => { router.push("/") }) .cat

我想使用此电子邮件登录admin@gmail.com已在我的Firebase身份验证中注册

因此,我写了登录认证,将登录,如果电子邮件和密码由firebase认证满意

const handleLogin = (e) => { 
e.preventDefault(); 
fire.auth()
  .signInWithEmailAndPassword(email, password)
  .then(() => { router.push("/") })
.catch((err) => {
    const message = err.message
    toast({
      title: "An error occured",
      position: "bottom-right",
      description: message,
      status: "error",
      duration: 2000,
      isClosable: true,
    })
  })
setEmail('')
setPassword('')
}
在那之后,我尝试使用我唯一的管理员电子邮件admin@gmail.com在成功登录到/admin dir后重定向页面,否则如果用户不是admin,将重定向到“/”或“/index”

这是我修改过的代码

const handleLogin = (e) => { 
e.preventDefault(); 
fire.auth()
  .signInWithEmailAndPassword(email, password)
  .then(() => { 
   fire.firestore().collection("user").where("email","==","admin@gmail.com")
    .get()
    .then((querySnapshot) => {
      querySnapshot.forEach((doc) => {
        if (doc.email === 'admin@gmail.com') {
          router.push("/admin")
        } else {
          router.push("/")
        }
      })
})
.catch((err) => {
    const message = err.message
    toast({
      title: "An error occured",
      position: "bottom-right",
      description: message,
      status: "error",
      duration: 2000,
      isClosable: true,
    })
  })
setEmail('')
setPassword('')
}

我无法解决这个问题,因为我对这个问题还很陌生,并且已经寻找了好几天的答案。我只想这样做,只需一个管理员来控制Web应用程序,并且有许多用户将使用它。

除了这一行,您的第二个示例中的代码看起来应该可以工作

if (doc.email === 'admin@gmail.com') {
应该是哪一个

if (doc.data().email === 'admin@gmail.com') {
然后可以将where子句设置为

where("email","==",email)
您的代码应该按预期工作