Created
October 14, 2018 04:29
-
-
Save iammarkps/aa954eba0b64dd024e7e5a05d2233445 to your computer and use it in GitHub Desktop.
AuthRequired
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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