Skip to content

Commit 7c2b1c8

Browse files
committed
added Google auth provider with popup
1 parent bccaba4 commit 7c2b1c8

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

frontend/src/assets/google.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/src/components/signin.jsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const useStyles = makeStyles((theme) => ({
5252

5353
export default function SignIn() {
5454
const classes = useStyles();
55-
const { login } = useAuth()
55+
const { login, googleLogin } = useAuth()
5656
const history = useHistory()
5757

5858
async function handleSubmit(e) {
@@ -71,6 +71,17 @@ export default function SignIn() {
7171
}
7272
}
7373

74+
async function handleGoogleSignin(e) {
75+
76+
googleLogin()
77+
.then(res=>{
78+
console.log('res: ', res);
79+
})
80+
.catch(err=> {
81+
console.log('err: ', err);
82+
})
83+
}
84+
7485
return (
7586
<Container component="main" maxWidth="xs">
7687
<CssBaseline />
@@ -130,6 +141,16 @@ export default function SignIn() {
130141
</Grid>
131142
</Grid>
132143
</form>
144+
<Button
145+
type="button"
146+
fullWidth
147+
variant="contained"
148+
color="primary"
149+
className={classes.submit}
150+
onClick={handleGoogleSignin}
151+
>
152+
Sign In With Google
153+
</Button>
133154
</div>
134155
<Box mt={8}>
135156
<Copyright />

frontend/src/context/AuthContext.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useContext, useState, useEffect } from "react"
22
import { auth } from "../firebase"
3+
import firebase from 'firebase/app'
34
import { userServices } from '../services/user'
45

56
const AuthContext = React.createContext()
@@ -20,6 +21,11 @@ export function AuthProvider({ children }) {
2021
return auth.signInWithEmailAndPassword(email, password)
2122
}
2223

24+
function googleLogin () {
25+
const provider = new firebase.auth.GoogleAuthProvider();
26+
return auth.signInWithPopup(provider)
27+
}
28+
2329
function logout() {
2430
return auth.signOut()
2531
}
@@ -63,6 +69,7 @@ export function AuthProvider({ children }) {
6369
const value = {
6470
currentUser,
6571
login,
72+
googleLogin,
6673
signup,
6774
logout,
6875
resetPassword,

0 commit comments

Comments
 (0)