AngularFire2 - 如何获取授权用户电子邮件?

AngularFire2 - How to get Auth User Email?

如何获取当前授权用户的电子邮件地址? Ofc

很容易得到他的 uID
constructor(public af: AngularFire){
           this.user = this.af.auth.getAuth().uid;
}

但是我收不到他的Email。我怎样才能得到这个?在 getAuth() 方法中,我可以获得 uId 和提供者编号。

要访问 email 属性,您首先需要访问 auth 属性。 (因为 getAuth() 将 return {auth { .... }} 如果你 json 它。

转换一个auth.displayName我自己用的是下面的方法。需要 string 包含 1 个或多个单词。如果只有 1 个单词,它会将其设置为空 firstnamelastname。在 2 个或更多单词上,第一个单词将是 firstnamelastname 之后的所有内容(由于 string 在空格上拆分,因此具有更多逻辑,并且尾随空格看起来更好长 lastname)

在方法本身中,我解释了如何处理“Edwin van der Sar”。

// Participant = {id: number, firstname: string, lastname: string}
    private splitName(part: Participant, fullname: String): Participant {
            // split the name by space (first last) (['Edwin','van','der','Sar']);
            let splittedName:Array<string> = fullname.split(' ');

            // if only one word is displayed (f.e. ivaro18) set it as lastname 
            // (improves search results later on)
            if(splittedName.length < 2) {
                part.lastname = splittedName[0];
            }
            // if first and last name are displayed
            else if (splittedName.length < 3) {
                part.firstname = splittedName[0];
                part.lastname = splittedName[1];
            }
            // if the user has a hard name
            else if (splittedName.length >= 3) {
                // first part will be the firstname (f.e. 'Edwin')
                part.firstname = splittedName[0];
                // loop through all other and concat them to be the lastname
                for(var i = 1; i < (splittedName.length); i++){
                    if(part.lastname != undefined){
                        // first part is already there, if it isnt the last part add a space ('der ')
                        if(!(i == (splittedName.length -1))) {
                            part.lastname += splittedName[i] +" ";
                        } else {
                            // it's the last part, don't add a space ('Sar')
                            part.lastname += splittedName[i];
                        }
                    }
                    // first part of the lastname ('van ')
                    else {
                        part.lastname = splittedName[i] +" ";
                    }

                }
            }
            return part;
    }

(很有可能可以改进,但它一点也不慢,所以它不是我的优先事项之一)