Skip to content

Instantly share code, notes, and snippets.

@dtinth
Last active July 8, 2017 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/8aa9680f19c2755dccfd88aeb36143d2 to your computer and use it in GitHub Desktop.
Save dtinth/8aa9680f19c2755dccfd88aeb36143d2 to your computer and use it in GitHub Desktop.
export class FirebaseAuth extends React.Component {
static propTypes = {
children: PropTypes.func.isRequired
}
auth = firebase.auth()
state = { user: this.auth.currentUser }
componentDidMount () {
this.unsubscribe = this.auth.onAuthStateChanged(user => {
this.setState({ user })
})
}
componentWillUnmount () {
this.unsubscribe()
}
render () {
return this.props.children(this.state.user)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment