简体   繁体   中英

How to receive user name and country with auth().createUserWithEmailAndPassword

Good day Developers. Please i am new to react native and i want to use firebase auth for a project. But i don't know how to accept user name and country with the normal auth().createUserWithEmailAndPassword method. Below is my code so far.. But it does work fine.

 import React, {createContext, useState} from 'react'; import { StyleSheet, ActivityIndicator, View, Text, Alert } from 'react-native' import auth from '@react-native-firebase/auth'; import firebase from '@react-native-firebase/app'; export const AuthContext = createContext(); export const AuthProvider = ({children}) => { const [user, setUser] = useState(null); return ( <AuthContext.Provider value={{ user, setUser, login: async (email, password) => { try { await auth().signInWithEmailAndPassword(email, password); } catch (e) { console.log(e); Alert.alert( e.message); } }, register: async (name, email, password) => { try { await auth().createUserWithEmailAndPassword(email, password); firebase.auth().currentUser.updateProfile({ displayName: name }); Alert.alert("Success ✅", "Account created successfully") return {}; } catch (e) { Alert.alert( e.message ); } }, forgot: async (email) => { try { await firebase.auth().sendPasswordResetEmail(email); Alert.alert("Success ✅", "A Password Recorvery Link has been sent to your mail.") } catch (e) { Alert.alert( e.message ); } }, logout: async () => { try { await auth().signOut(); } catch (e) { Alert.alert( e.message ); } }, sendver: async () => { try { await firebase.auth().currentUser.sendEmailVerification(); } catch (e) { Alert.alert( e.message ); } }, }}> {children} </AuthContext.Provider> ); };

I will really appreaciate if anyone can help. thanks so much.

Try this way

firebase.auth().signInWithEmailAndPassword("abc@gmail.com", "******")
  .then(function(user) {
     // Success 
   })
.catch(function(error) {
    // Error Handling
});

Note: Save user info on success in your database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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