Skip to content

Commit b612a46

Browse files
committed
feat: Add github auth
1 parent 19a3dee commit b612a46

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/features/auth/api/Config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { initializeApp } from 'firebase/app'
2-
import { getAuth, GoogleAuthProvider } from 'firebase/auth'
2+
import { getAuth, GithubAuthProvider, GoogleAuthProvider } from 'firebase/auth'
33

44
// TODO This is a temporary firebase project config, to be changed later.
55
const firebaseConfig = {
@@ -15,6 +15,7 @@ const firebaseConfig = {
1515
// Initialize Firebase
1616
const app = initializeApp(firebaseConfig)
1717
const auth = getAuth(app)
18-
const provider = new GoogleAuthProvider()
18+
const googleProvider = new GoogleAuthProvider()
19+
const githubProvider = new GithubAuthProvider()
1920

20-
export { auth, provider }
21+
export { auth, githubProvider, googleProvider }

src/features/auth/components/AuthModal.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth'
1+
import { GithubAuthProvider, GoogleAuthProvider, signInWithPopup } from 'firebase/auth'
22
import { FaGithub, FaGoogle } from 'react-icons/fa'
33
import ReactModal from 'react-modal'
44
import toast from 'react-simple-toasts'
5-
import { auth, provider } from '../api/Config'
5+
import { auth, githubProvider, googleProvider } from '../api/Config'
66

77
type AuthModalProps = {
88
showAuth: boolean
@@ -11,7 +11,7 @@ type AuthModalProps = {
1111

1212
export const AuthModal = ({ showAuth, setShowAuth }: AuthModalProps) => {
1313
const signInWithGoogle = () => {
14-
signInWithPopup(auth, provider)
14+
signInWithPopup(auth, googleProvider)
1515
.then((result) => {
1616
const credential = GoogleAuthProvider.credentialFromResult(result)
1717
// TODO save this token in user settings maybe!
@@ -24,6 +24,22 @@ export const AuthModal = ({ showAuth, setShowAuth }: AuthModalProps) => {
2424
toast("We couldn't login to you Google account!!", { theme: 'failure' })
2525
})
2626
}
27+
28+
const signInWithGithub = () => {
29+
signInWithPopup(auth, githubProvider)
30+
.then((result) => {
31+
const credential = GithubAuthProvider.credentialFromResult(result)
32+
// TODO save this token in user settings maybe!
33+
const token = credential.accessToken
34+
// The signed-in user info.
35+
const user = result.user
36+
console.log(user)
37+
})
38+
.catch((error) => {
39+
toast("We couldn't login to you Github account!!", { theme: 'failure' })
40+
})
41+
}
42+
2743
return (
2844
<ReactModal
2945
isOpen={showAuth}
@@ -50,12 +66,11 @@ export const AuthModal = ({ showAuth, setShowAuth }: AuthModalProps) => {
5066
</p>
5167
</div>
5268
<div>
53-
<button type="button" className="extraTextWithIconBtn">
69+
<button className="extraTextWithIconBtn" onClick={signInWithGithub}>
5470
<FaGithub />
5571
Sign in with Github
5672
</button>
5773
<button
58-
type="button"
5974
className="extraTextWithIconBtn"
6075
style={{ marginLeft: 10 }}
6176
onClick={signInWithGoogle}>

0 commit comments

Comments
 (0)