Skip to content

Commit 71cd2e6

Browse files
committed
feat: Add google auth.
1 parent b25327a commit 71cd2e6

4 files changed

Lines changed: 692 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"axios-cache-adapter": "^2.7.3",
1414
"country-emoji": "^1.5.4",
1515
"dompurify": "^2.2.7",
16+
"firebase": "^11.2.0",
1617
"htmlparser2": "^8.0.1",
1718
"jsonpath": "^1.1.1",
1819
"normalize.css": "^8.0.1",

src/features/auth/api/Config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { initializeApp } from 'firebase/app'
2+
import { getAuth, GoogleAuthProvider } from 'firebase/auth'
3+
4+
// TODO This is a temporary firebase project config, to be changed later.
5+
const firebaseConfig = {
6+
apiKey: 'AIzaSyCpD2SbQnCCDjmAPasQ8q5jPcxf5lQLwYI',
7+
authDomain: 'hackertab-418813.firebaseapp.com',
8+
projectId: 'hackertab-418813',
9+
storageBucket: 'hackertab-418813.firebasestorage.app',
10+
messagingSenderId: '249160525821',
11+
appId: '1:249160525821:web:e729de3eadc14d2242db94',
12+
measurementId: 'G-NTMXFLMF00',
13+
}
14+
15+
// Initialize Firebase
16+
const app = initializeApp(firebaseConfig)
17+
const auth = getAuth(app)
18+
const provider = new GoogleAuthProvider()
19+
20+
export { auth, provider }

src/features/auth/components/AuthModal.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
import { GoogleAuthProvider, signInWithPopup } from 'firebase/auth'
12
import { FaGithub, FaGoogle } from 'react-icons/fa'
23
import ReactModal from 'react-modal'
4+
import toast from 'react-simple-toasts'
5+
import { auth, provider } from '../api/Config'
36

47
type AuthModalProps = {
58
showAuth: boolean
69
setShowAuth: (show: boolean) => void
710
}
811

912
export const AuthModal = ({ showAuth, setShowAuth }: AuthModalProps) => {
13+
const signInWithGoogle = () => {
14+
signInWithPopup(auth, provider)
15+
.then((result) => {
16+
const credential = GoogleAuthProvider.credentialFromResult(result)
17+
// TODO save this token in user settings maybe!
18+
const token = credential.accessToken
19+
// The signed-in user info.
20+
const user = result.user
21+
console.log(user)
22+
})
23+
.catch((error) => {
24+
toast("We couldn't login to you Google account!!", { theme: 'failure' })
25+
})
26+
}
1027
return (
1128
<ReactModal
1229
isOpen={showAuth}
@@ -37,7 +54,11 @@ export const AuthModal = ({ showAuth, setShowAuth }: AuthModalProps) => {
3754
<FaGithub />
3855
Sign in with Github
3956
</button>
40-
<button type="button" className="extraTextWithIconBtn" style={{ marginLeft: 10 }}>
57+
<button
58+
type="button"
59+
className="extraTextWithIconBtn"
60+
style={{ marginLeft: 10 }}
61+
onClick={signInWithGoogle}>
4162
<FaGoogle />
4263
Sign in with Google
4364
</button>

0 commit comments

Comments
 (0)