簡體   English   中英

如何知道電子郵件是否已經在Firebase身份驗證JavaScript中注冊?

[英]How to know if the email has already been registered in firebase authentication, javascript?

我正在為用戶更新電子郵件,但首先我需要知道該電子郵件先前是否已在Firebase身份驗證中注冊。

通過這種方式,我更新了電子郵件:

 if(administrador.correo != vm.editedItem.correo){
       console.log("ESTA ACTUALIZANDO CORREO");
       console.log(vm.editedItem);
       firebase.auth().signInWithEmailAndPassword(vm.editedItem.correo, vm.editedItem.contrasenia)
                                    .then(function(userCredential) {
                                        console.log("USER CREDENTIAL");
                                        console.log(userCredential);
                                        userCredential.user.updateEmail(vm.editedItem.correo)
                                        .then(function() {
                                            console.log("email update");
                                        // Update successful.
                                        }).catch(function(error) {
                                            console.log("ERROR");
                                            console.log(error);
                                        // An error happened.
                                        });
                                    })
                              }

但是在更新電子郵件之前,我必須驗證它是否已經存在,該電子郵件是否存在,因為不允許更新該郵件以及該電子郵件不存在,因此我要更新該電子郵件。

事先非常感謝。

檢查以下代碼。 我認為您正在嘗試更改登錄時使用的相同電子郵件。我做了一些小的更改和評論。

if (administrador.correo != vm.editedItem.correo) {
    console.log("ESTA ACTUALIZANDO CORREO");
    console.log(vm.editedItem);
    firebase.auth().signInWithEmailAndPassword(vm.currentItem.correo, vm.editedItem.contrasenia)  // sign in with current email and password
        .then(function (userCredential) {
            console.log("USER CREDENTIAL");
            console.log(userCredential);
            userCredential.user.updateEmail(vm.editedItem.correo)  // update new email
                .then(function () {
                    console.log("email update");
                    // Update successful.
                }).catch(function (error) {
                    console.log("ERROR");
                    console.log(error);
                    // An error happened.
                    // if updated user email already exists, it returns error code: auth/email-already-in-use
                });
        })
}

點擊此鏈接以獲取更多更新

如果發生錯誤,請檢查已使用的錯誤代碼auth / email。

或者,使用admin.auth().getUserByEmail() 構建到雲函數並從您的應用中調用一個函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM