Last active
December 21, 2015 19:26
-
-
Save josefrichter/5e415f77d8f018d1a26e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
currentUser: null, | |
joinError: null, | |
}; | |
} | |
componentWillMount() { | |
var _this = this; // TODO can be avoided? | |
/** | |
* onAuth fires anytime the auth status of this user changes | |
*/ | |
_fbBase.onAuth((authData) => { | |
if (!authData) { | |
// console.log('unauthenticated user'); | |
this.setState({ | |
user: null, | |
}); | |
return; | |
} | |
console.log('authData', authData); | |
var newUserID = authData.facebook.id; | |
// save new user to database | |
var newUser = _fbUsers.child(newUserID).update(authData, (error) => { // the fat arrouw here should do the trick? | |
if (error) { | |
alert("Data could not be saved." + error); | |
} else { | |
console.log("Data saved successfully.", this); | |
this.setState({currentUser: authData}); // TODO can be avoided? | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment