Skip to content

createUserWithEmailAndPassword does not return user credentials after creation #251

Closed
@grubersjoe

Description

@grubersjoe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions