Skip to content

createUserWithEmailAndPassword does not return user credentials after creation #251

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
grubersjoe opened this issue Jun 28, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@grubersjoe
Copy link

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.

@chrisbianca
Copy link
Contributor

@grubersjoe Apologies for the delay. This seems like a sensible idea to me and would welcome a PR!

@chrisbianca chrisbianca added the enhancement New feature or request label Nov 4, 2022
@grubersjoe
Copy link
Author

Hey. Thank's for adding this. Highly appreciated :)!

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants