react-firebase-hooks
react-firebase-hooks copied to clipboard
createUserWithEmailAndPassword does not return user credentials after creation
Hey. Very nice project, thanks for maintaining this!
I'm using the createUserWithEmailAndPassword() hook, but I've noticed that it does not return the user credentials like in this Firebase example. I think this is really useful when you want to immediately set data for the new user. In my case I want to set an username that is entered in the registration form:
import { createUserWithEmailAndPassword } from 'firebase/auth';
const onSubmit: SubmitHandler<RegisterForm> = data => {
setLoading(true);
createUserWithEmailAndPassword(firebaseAuth, data.email, data.password)
.then(credentials => setUserName(credentials.user.uid, data.name))
.catch(setError)
.finally(() => setLoading(false));
};
The above version uses createUserWithEmailAndPassword from firebase/auth directly but I'd love if the hook would support this out of the box. Simply returning the user inside the hook should be sufficient:
const signInWithEmailAndPassword = async (
email: string,
password: string,
) => {
setLoading(true);
setError(undefined);
try {
const user = await firebaseSignInWithEmailAndPassword(
auth,
email,
password,
);
setLoggedInUser(user);
return user; // <<<
} catch (err) {
setError(err as AuthError);
} finally {
setLoading(false);
}
};
What do you think? I can also open a PR if you like.