the-road-to-react-with-firebase / react-firebase-authentication

🔥 Boilerplate Project for Authentication with Firebase in React.
https://www.robinwieruch.de
1.02k stars 298 forks source link

SignUp page doesn't redirect #6

Closed spencexyz closed 6 years ago

spencexyz commented 6 years ago

event.preventDefault() doesn't appear to be working on the SignUp page, which causes the page to refresh and the user is never redirected.

rwieruch commented 6 years ago

Hm, I never experienced this nor did anybody else. Why do you think that it doesn't work?

spencexyz commented 6 years ago

Hey, thanks for getting back to me. I just realized I changed something in the doCreateUser in db.js.

When I change it to this:

export const doCreateUser = (id, fullname, username, email) => {
  db.ref(`users/${username}`).set({
    fullname,
    email,
  });
}

it doesn't work anymore. Do you know why this might be?

spencexyz commented 6 years ago

It looks like my addition of {}broke it by not returning the promise. Then I get Can't call setState (or forceUpdate) on an unmounted component. in the console, which went away when I removed // this.setState(() => ({ ...INITIAL_STATE }));. Thanks for the quick response, sorry about opening a bug for something that was user error.

rwieruch commented 6 years ago

No worries. Glad that you've figured out the issue :)

spyro254 commented 5 years ago

Just to clarify, in case anyone comes into contact with this issue. The AUTH API within the firebase.js file uses fat arrow functions without curly braces. If curly braces are introduced, a return statement is required in order for the promise to be returned for the .then function in the SignUp component.

.then is undefined in the following: doCreateUserWithEmailAndPassword = (email, password) => { this.auth.createUserWithEmailAndPassword(email, password); }

the following options return a valid response:

(return statement added) doCreateUserWithEmailAndPassword = (email, password) => { return this.auth.createUserWithEmailAndPassword(email, password); }

or (no curly braces) doCreateUserWithEmailAndPassword = (email, password) => this.auth.createUserWithEmailAndPassword(email, password);

Correct me if I'm wrong! (Amazing work, by the way)