Skip to content

Instantly share code, notes, and snippets.

@manakuro
Last active January 18, 2020 01:19
Show Gist options
  • Save manakuro/0ec0a4a40f868c4ee974a3bd616353d9 to your computer and use it in GitHub Desktop.
Save manakuro/0ec0a4a40f868c4ee974a3bd616353d9 to your computer and use it in GitHub Desktop.
// ...
const SignUp: React.FC = () => {
// ...
useEffect(() => {
firebase.auth().onAuthStateChanged(user => {
if (user) {
// user signed in
} else {
// user not signed in
}
})
}, [])
const handleSignUpWithGitHub = useCallback(async () => {
const provider = new firebase.auth.GithubAuthProvider()
try {
const currentUser = await firebase.auth().currentUser
const res = currentUser
? await currentUser.linkWithPopup(provider)
: await firebase.auth().signInWithPopup(provider)
console.log('res: ', res)
} catch (err) {
// error handling
console.error(err)
}
}, [])
// ...
return (
// ...
<Grid container spacing={2}>
<Grid item xs={12}>
<GithubLoginButton
className={classes.github}
onClick={handleSignUpWithGitHub}>
<span className={classes.githubText}>Sign up with Github</span>
</GithubLoginButton>
</Grid>
// ...
)
}
export default SignUp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment