我如何獲得當前的Auth用戶電子郵件? OFc很容易得到他的uID,通過AngularFire2 - 如何獲得Auth用戶電子郵件?
constructor(public af: AngularFire){
this.user = this.af.auth.getAuth().uid;
}
但我不能得到他的電子郵件。我怎麼能得到這個?在getAuth()方法中,我可以獲得uId和提供者編號。
我如何獲得當前的Auth用戶電子郵件? OFc很容易得到他的uID,通過AngularFire2 - 如何獲得Auth用戶電子郵件?
constructor(public af: AngularFire){
this.user = this.af.auth.getAuth().uid;
}
但我不能得到他的電子郵件。我怎麼能得到這個?在getAuth()方法中,我可以獲得uId和提供者編號。
要訪問email
屬性,您首先需要訪問auth
屬性。 (因爲getAuth()
將返回{auth { .... }}
,如果你的JSON它。
要轉換auth.displayName
我自己使用下面的方法。這將需要一個string
持有1個或多個單詞。如果只有1個字,就會將其設置爲所述lastname
用空firstname
。在2分或更多的話,第一個字將是firstname
和一切lastname
(與由於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;
}
(很可能可以改善,但所以這不是我的priorites之一,它不是在所有慢)
請不要恨我,但..我怎麼能創造這個用戶?我有這樣的方法http://pastebin.com/eBFwusbk。 – qwerty1234567
不要擔心哈哈。但我不知道答案,我只使用'angularfire2'來驗證和檢索社交媒體的名稱/電子郵件。我不使用電子郵件密碼登錄 – Ivaro18
沒問題的男人,愛幫忙。如果對你很重要,你應該考慮在新問題中提出 – Ivaro18
嘗試'this.af.auth.getAuth()。auth.email' – Ivaro18
哦我的上帝..非常感謝你。<3 – qwerty1234567
還有一個問題。我可以通過他的電子郵件和密碼創建用戶嗎?我想在那裏也姓名。 – qwerty1234567