Skip to content

Commit

Permalink
add: google auth
Browse files Browse the repository at this point in the history
  • Loading branch information
sambit-sankalp committed Sep 13, 2021
1 parent 1fa86a0 commit 56ddedc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/AuthScreens/SignIn.jsx
Expand Up @@ -67,7 +67,7 @@ const SignIn = () => {

const submitHandler = (e) => {
e.preventDefault();
dispatch(signin({ email: values.email, password: values.password }));
dispatch(signin());
};

return (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/config/firebase.js
Expand Up @@ -14,5 +14,6 @@ var firebaseConfig = {
firebase.initializeApp(firebaseConfig);
export const firestore = firebase.firestore();
export const auth = firebase.auth();
export const provider = new firebase.auth.GoogleAuthProvider();

export default firebase;
22 changes: 15 additions & 7 deletions frontend/src/store/actions/authActions.js
Expand Up @@ -9,17 +9,25 @@ import {
SIGNUP_SUCCESS,
SIGNUP_REQUEST,
} from "../constants/authConstants";
import { auth, firestore } from "../../config/firebase";
import { auth, firestore, provider } from "../../config/firebase";

export const signin = (credentials) => async (dispatch) => {
export const signin = () => async (dispatch) => {
try {
dispatch({ type: LOGIN_REQUEST });

await auth
.signInWithEmailAndPassword(credentials.email, credentials.password)
.then((userCredentials) => {
dispatch({ type: LOGIN_SUCCESS });
});
// await auth
// .signInWithEmailAndPassword(credentials.email, credentials.password)
// .then((userCredentials) => {
// dispatch({ type: LOGIN_SUCCESS });
// });

await auth.signInWithPopup(provider).then((result) => {
var credential = result.credential;
var token = credential.accessToken;
var user = result.user;
console.log(user);
})

} catch (error) {
dispatch({
type: LOGIN_FAIL,
Expand Down

0 comments on commit 56ddedc

Please sign in to comment.