Skip to content

Commit 57345d6

Browse files
queervioletqueerviolet
queerviolet
authored and
queerviolet
committed
WIP
1 parent f7e0d02 commit 57345d6

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

app/components/WhoAmI.jsx

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import React from 'react'
2+
import firebase from 'APP/fire'
3+
const auth = firebase.auth()
24

3-
export const WhoAmI = ({ user, logout }) => (
5+
export const WhoAmI = ({ user }) => (
46
<div className="whoami">
57
<span className="whoami-user-name">{user && user.name}</span>
6-
<button className="logout" onClick={logout}>Logout</button>
78
</div>
89
)
910

1011
import {logout} from 'APP/app/reducers/auth'
1112
import {connect} from 'react-redux'
1213

13-
export default connect(
14-
({ auth }) => ({ user: auth }),
15-
{logout},
16-
)(WhoAmI)
14+
export default class extends React.Component {
15+
componentDidMount() {
16+
this.unsubscribe = auth.onAuthStateChanged(user => this.setState({user}))
17+
}
18+
componentWillUnmount() {
19+
this.unsubscribe()
20+
}
21+
render() {
22+
return (
23+
<WhoAmI user={this.state.user}/>
24+
)
25+
}
26+
}

app/main.jsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import Jokes from './components/Jokes'
99
import Login from './components/Login'
1010
import WhoAmI from './components/WhoAmI'
1111
import NotFound from './components/NotFound'
12+
import firebase from 'APP/fire'
1213

13-
const ExampleApp = connect(
14-
({ auth }) => ({ user: auth })
15-
)(
16-
({ user, children }) =>
17-
<div>
18-
<nav>
19-
{user ? <WhoAmI/> : <Login/>}
20-
</nav>
21-
{children}
22-
</div>
23-
)
14+
firebase.auth().onAuthStateChanged(user => user || firebase.auth().signInAnonymously())
15+
16+
const ExampleApp = ({children}) =>
17+
<div>
18+
<nav>
19+
<WhoAmI/>
20+
</nav>
21+
{children}
22+
</div>
2423

2524
render(
2625
<Provider store={store}>

dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const app = require('.')
88
, chalk = require('chalk'), {bold} = chalk
99
, {red, green, blue, cyan, yellow} = bold
1010
, dev = module.exports = () => run({
11-
server: task(app.package.scripts['start-watch'], {color: blue}),
11+
server: task(app.package.scripts['start'], {color: blue}),
1212
build: task(app.package.scripts['build-watch'], {color: green}),
1313
lint: task(app.package.scripts['lint-watch'], {color: cyan}),
1414
test: task(app.package.scripts['test-watch'], {color: yellow})

fire/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const firebase = require('firebase')
2+
3+
// Initialize Firebase
4+
var config = {
5+
apiKey: 'AIzaSyBzz-Wq2dzMgM7E8cdSYnYoX5fbVUT-XQo',
6+
authDomain: 'firebones-6bc2a.firebaseapp.com',
7+
databaseURL: 'https://firebones-6bc2a.firebaseio.com',
8+
projectId: 'firebones-6bc2a',
9+
storageBucket: 'firebones-6bc2a.appspot.com',
10+
messagingSenderId: '1030378391678'
11+
}
12+
13+
module.exports = firebase.initializeApp(config)

0 commit comments

Comments
 (0)