Skip to content

Instantly share code, notes, and snippets.

@krizzu
Created October 2, 2017 07:52
Show Gist options
  • Save krizzu/92890c9cbb506fd08fb1975bd7c319ed to your computer and use it in GitHub Desktop.
Save krizzu/92890c9cbb506fd08fb1975bd7c319ed to your computer and use it in GitHub Desktop.
Example for simple authentication using RNFirebase
// ...
// Inside our Component's class
_authenticateUser = async () => {
const { firebase } = this.props; // Parent passes reference to Firebase through props
const { userPassword, userEmail } = this.state;
let userInfo = null;
try {
userInfo = await firebase.auth().signInWithEmailAndPassword(userEmail, userPassword)
} catch(error) {
// Error will contain information like Invalid credentials or User does not exist
return this.setState(() => ({
authError: error.toString(),
isFetchingAuth: false,
isAuthenticated: false
}))
}
// We're authenticated!
// We don't need to store userInfo, just check if value is not null.
this.setState(() => ({
isFetchingAuth: false,
isAuthenticated: !!userInfo
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment