Last active
January 18, 2020 01:19
-
-
Save manakuro/0ec0a4a40f868c4ee974a3bd616353d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ... | |
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