Skip to content

Instantly share code, notes, and snippets.

@iammarkps
Created October 14, 2018 04:29
Show Gist options
  • Save iammarkps/aa954eba0b64dd024e7e5a05d2233445 to your computer and use it in GitHub Desktop.
Save iammarkps/aa954eba0b64dd024e7e5a05d2233445 to your computer and use it in GitHub Desktop.
AuthRequired
import React from 'react'
import * as fiery from 'fiery'
import { firebase } from './firebase'
import AdminPanel from './adminPanel'
export class AuthRequired extends React.Component {
render() {
return (
<fiery.Auth>
{authState =>
fiery.unwrap(authState, {
loading: () => <div>Loading authentication state...</div>,
error: () => <h1>ERROR!</h1>,
completed: user => {
if (user) {
return <AdminPanel />
} else {
return (
<div>
You must sign in to continue:{' '}
<button onClick={authenticateWithGoogle}>
Sign in with Google
</button>
</div>
)
}
}
})
}
</fiery.Auth>
)
}
}
function authenticateWithGoogle() {
firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment