Firebase allows users to sign in with their existing social accounts like Google, GitHub, Facebook, and more.
We use the GoogleAuthProvider and signInWithPopup (or signInWithRedirect).
import { auth } from "../lib/firebase";
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
const provider = new GoogleAuthProvider();
const signInWithGoogle = async () => {
try {
const result = await signInWithPopup(auth, provider);
const user = result.user;
console.log("Logged in with Google:", user.displayName);
} catch (error) {
console.error("Social Auth Error:", error.message);
}
};The process is almost identical for other social providers:
new GithubAuthProvider()new FacebookAuthProvider()new TwitterAuthProvider()