2017-09-28 80 views
0

我正在使用React Native製作的應用程序中的註冊表屏幕上工作。我正在使用Firebase身份驗證來創建新用戶。React Native + Firebase身份驗證 - displayName

在登錄屏幕上,我使用.signInWithEmailAndPassword(訪問帳戶),並在註冊屏幕上使用.createUserWithEmailAndPassword(創建用戶)以及閱讀有關Firebase身份驗證的文章,我知道我可以使用displayName接收用戶名,用photoUrl接收用戶的照片。

我想要做的是使用用戶名,電子郵件和密碼創建一個新用戶。即使閱讀關於這個問題的文章,我也不知道這樣做的方法。

這是我的代碼:

signup() { 
    this.setState({ 
    // When waiting for the firebase server show the loading indicator. 
    loading: true 
    }); 
    // Make a call to firebase to create a new user. 
    this.props.firebaseApp.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((userData) => { 
    // then and catch are methods that we call on the Promise returned from 
    // createUserWithEmailAndPassword 
    Alert.alert('Success', 'Congrats!', [{text: 'OK!', onPress: this.dismiss}]); 
    this.setState({ 
    // Clear out the fields when the user logs in and hide the progress indicator. 
    email: '', 
    password: '', 
    loading: false 
    }); 
    AsyncStorage.setItem('userData', JSON.stringify(userData)); 
    this.props.navigator.push({ 
    component: Account 
    }); 
}).catch((error) => { 
    // Leave the fields filled when an error occurs and hide the progress indicator. 
    this.setState({ 
     loading: false 
    }); 
    Alert.alert('Ops', 'Error: ' + error.message, [{text: 'OK!', onPress: this.dismiss}]); 
    }); 
} 

基本上我想創建一個使用火力地堡認證的用戶名,電子郵件地址和密碼的新用戶。

你們中的任何人都可以給我舉一個例子,說明如何使用用戶名,電子郵件和密碼創建用戶?

如果你想看看我正在嘗試做什麼,我創建了一個項目來提高我對React Native的瞭解? https://github.com/JoaoVRodrigues01/React-Native-Codec-App

回答

1

如果你想支持登錄與用戶名/密碼:

註冊時,您可以要求輸入用戶名,電子郵件地址和密碼。 您使用createUserWithEmailAndPassword創建帳戶,然後在確保用戶名唯一性的情況下,在Firebase數據庫中保存用戶名到電子郵件的映射。

用戶下次使用用戶名和密碼登錄時,可以從用戶名中獲得電子郵件,然後使用提供的電子郵件和密碼獲取電子郵件地址signInWithEmailAndPassword

+0

嘿,謝謝你的回答!在登錄屏幕中,用戶將使用電子郵件和密碼進入帳戶,並且在註冊屏幕中,用戶將使用姓名,電子郵件和密碼創建一個帳戶。我想在註冊表中詢問用戶名以在屏幕上返回用戶信息,將會顯示用戶帳戶信息,例如用戶名和電子郵件。 –

+0

我很抱歉,但我不明白你的用例。 – bojeil

+0

基本上我想用用戶名,電子郵件和密碼使用Firebase身份驗證創建一個用戶。但沒問題。不管怎樣,謝謝你! –