简体   繁体   English

Firebase 身份验证:通过 Email 查找用户

[英]Firebase Authentication : Lookup a user by Email

I am using Firebase Authentication with Email and Password我正在使用Firebase 身份验证与 Email 和密码

I would like to know if i can 'lookup' a user by email only while also not being signed in as a user我想知道我是否可以通过 email “查找”用户,同时也不能以用户身份登录

The reason I'd like to do this is, is to simply identify if I am already a user of the system, using an email address only我想这样做的原因是,仅使用 email 地址来确定我是否已经是系统的用户

I looked at this older thread but it appears to be the previous version of Firebase我查看了这个较旧的线程,但它似乎是 Firebase 的先前版本

Is it possible to do this in the current Firebase, or my alternative would be to keep this information available (and open to all?) to find out if a given email is part of my system?是否可以在当前的 Firebase 中执行此操作,或者我的替代方法是保持此信息可用(并对所有人开放?)以确定给定的 email 是否是我系统的一部分?

I use fetchProvidersForEmail(email) and if the result return as empty array then, this email hasn't been use to sign up.我使用 fetchProvidersForEmail(email) ,如果结果返回为空数组,则该电子邮件尚未用于注册。

 firebase.auth().fetchProvidersForEmail(email) .then(providers => { if (providers.length === 0) { // this email hasn't signed up yet } else { // has signed up } });

The new method of creating users with email password returns a value whether the given email address is already in use.使用电子邮件密码创建用户的新方法会返回一个值,无论给定的电子邮件地址是否已被使用。 See here这里

You can look up user information by email:您可以通过电子邮件查找用户信息:

firebase.auth().getUserByEmail(email)
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully fetched user data:', userRecord.toJSON());
  })
  .catch(function(error) {
   console.log('Error fetching user data:', error);
  });

Retrieve user data 检索用户数据

import { fetchSignInMethodsForEmail } from 'firebase/auth'从 'firebase/auth' 导入 { fetchSignInMethodsForEmail }

fetchSignInMethodsForEmail(auth, registerEamil).then((result) =>{
        console.log("result", result);
        if (result.length === 0) {
            Navigate("/authentication/select_role/" + 
      registerEamil)
        } else {
            Navigate('/')
        }
  

As for today 2021 Nov. 18th, there is no way provided by the Firebase SDK to fetch a user by email.至于今天2021年11月18日,Firebase SDK没有办法通过email来获取用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM