{currentFood.description}
{errors.error}
} + + + + ); }; diff --git a/src/Components/Login/useAuth.js b/src/Components/Login/useAuth.js index b8f03cd..fca3406 100644 --- a/src/Components/Login/useAuth.js +++ b/src/Components/Login/useAuth.js @@ -34,6 +34,10 @@ export const PrivateRoute = ({ children, ...rest }) => { ); } +const getUser = user => { + const { displayName, email, photoURL } = user + return { name: displayName, email, photo: photoURL } +} const Auth = () => { const [user, setUser] = useState(null); useEffect(() => { @@ -68,11 +72,24 @@ const Auth = () => { }); - - - } + const signInWithGoogle = () => { + const provider = new firebase.auth.GoogleAuthProvider() + return firebase.auth().signInWithPopup(provider) + .then(res => { + // console.log(res); + const signedInUser = getUser(res.user) + setUser(signedInUser) + return res.user + }) + .catch(err => { + // console.log(err) + setUser(null) + return err.message + }); + } + const signOut = () => { return firebase.auth().signOut() .then(res => setUser(null)) @@ -81,6 +98,7 @@ const Auth = () => { user, signIn, signUp, + signInWithGoogle, signOut } } diff --git a/src/Images/login-with-google-button.png b/src/Images/login-with-google-button.png new file mode 100644 index 0000000..716e0b7 Binary files /dev/null and b/src/Images/login-with-google-button.png differ diff --git a/src/Images/logout.jpg b/src/Images/logout.jpg new file mode 100644 index 0000000..6a73c85 Binary files /dev/null and b/src/Images/logout.jpg differ