I am currently developping an app using react native and i could manage to have a login and sign up page but my problem is the following. After create user with email and password using firebase method, i would like to update the profile info (displayName) in order to display it in the home page. But it seems that the page redirect to the home page after sign up without the update done
I have set a listener on my navigator stack to display login/signup pages or Home page regarding the value of user.
the Update is correctly set if i close the app and reload it after the first sign up success.
my code is the following the main stack code
function onAuthStateChange(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChange);
return subscriber;
}, [];
if (initializing) {
return <LoadingScreen />
if (!user) {
return (
<NavigationCOntainer>
<AuthStackScreen />
</NavigationCOntainer>
);
}
return (
<NavigationCOntainer>
<DrawerStackScreen />
</NavigationCOntainer>
the code to handle the sign up method :
function handgleRegister() {
auth()
.createUserWithEmailAndPassword(email, password)
.then(userCred => {
return userCred.user.updateProfile({
displayName: name,
});
})
.catch(e => {
...
...
});
}
the code in the Home page, i also set a listener of user. I also have tried by calling the method : auth().currentUser; But i got the same problem, the displayName at the first display was set to null and i had to close and reload the app to be able to display it.
function onAuthStateChange(user) {
console.log(user);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChange);
return subscriber;
}, [];
the result of the log shows that displayName is null so i assume the sign up process redirect to the home before updating the value.
Does someone has an idea how i can manage to get the update value on the Home page screen?
Thanks in advance