Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import { auth } from './firebase';
function Login() {
const login = async () => {
const provider = new auth.GoogleAuthProvider();
try {
await auth().signInWithPopup(provider);
} catch (e) {}
};
try {
await auth().signInWithPopup(provider);
const user = await auth().currentUser;
setUser(user);
} catch(e) {}
React.useEffect(() => {
return auth().onAuthStateChanged((user) => {
if (user) {
setUser(user);
} else {
setUser(null);
}
});
}, []);