Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Last active May 14, 2019 17:26
Show Gist options
  • Save samcorcos/7fb3b995c682e3c50ba6d7a6046e0d89 to your computer and use it in GitHub Desktop.
Save samcorcos/7fb3b995c682e3c50ba6d7a6046e0d89 to your computer and use it in GitHub Desktop.
import React from 'react'
import { Context } from '../lib/context'
import { firebase } from '../lib/firebase'
export default class Home extends React.Component {
constructor (props) {
super(props)
this.state = {
email: '',
password: ''
}
}
render () {
return (
<Context.Consumer>
{store => {
console.log(store)
if (!store.currentUser.uid) {
return (
<div>
<input placeholder='Email' onChange={e => this.setState({ email: e.target.value })} value={this.state.email} />
<input type='password' placeholder='Password' onChange={e => this.setState({ password: e.target.value })} value={this.state.password} />
<button onClick={() => firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password)}>Submit</button>
</div>
)
}
return (
<div>
<div>Email: {store.currentUser.email}</div>
<button onClick={() => store.signOut()}>Sign out</button>
</div>
)
}}
</Context.Consumer>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment