Skip to content
Permalink
Browse files

Support firebase authentication

  • Loading branch information...
dusty-phillips committed Aug 27, 2018
1 parent c863c09 commit e5657a6cfc12b8727ec3c87116498a781d4945aa
Showing with 61 additions and 1 deletion.
  1. +10 −1 src/App.js
  2. +51 −0 src/components/AuthButton.js
@@ -1,8 +1,17 @@
import React, { Component } from 'react'
import { Provider } from "react-redux"

import store from "./redux/store"
import AuthButton from "./components/AuthButton"


class App extends Component {
render() {
return <div>Hello World</div>
return (
<Provider store={store}>
<AuthButton />
</Provider>
)
}
}

@@ -0,0 +1,51 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase'


class AuthButton extends Component {
static propTypes = {
auth: PropTypes.object,
firebase: PropTypes.shape({
login: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
}),
}

render() {
if (!isLoaded(this.props.auth)) {
return null
}
if (isEmpty(this.props.auth)) {
return (
<div>
<button
onClick={
() => this.props.firebase.login({ provider: 'facebook', type: 'popup' })
}
>Log in with Facebook</button>
</div>
)
}
return <button
style={{ width: "20rem" }}
onClick={() => this.props.firebase.logout()}
> Logout</button >

}
}

const mapStateToProps = state => {
return { auth: state.firebase.auth }
}

const mapDispatchToProps = {
}


export default compose(
connect(mapStateToProps, mapDispatchToProps),
firebaseConnect()
)(AuthButton)

0 comments on commit e5657a6

Please sign in to comment.
You can’t perform that action at this time.