Other Auth Providers
Set up additional authentication methods including email/password, GitHub, and anonymous sign-in.
Firebase Authentication supports multiple sign-in methods. Depending on the project PRD, you may need to implement different authentication providers.
Always check the project's PRD to understand which authentication methods are required. Some projects may only need email/password, while others require social login options.
The most basic authentication method. Users create an account with their email and a password.
Enabling Email/Password
- Go to Authentication Settings
Firebase Console → Authentication → Sign-in method
- Enable Email/Password
Click on Email/Password and toggle it on
- Optional: Enable Email Link
You can also enable passwordless sign-in via email links
Implementation
import {
getAuth,
createUserWithEmailAndPassword,
signInWithEmailAndPassword
} from 'firebase/auth';
const auth = getAuth();
// Create new account
async function signUp(email, password) {
try {
const userCredential = await createUserWithEmailAndPassword(
auth, email, password
);
return userCredential.user;
} catch (error) {
console.error('Sign up error:', error.message);
throw error;
}
}
// Sign in existing user
async function signIn(email, password) {
try {
const userCredential = await signInWithEmailAndPassword(
auth, email, password
);
return userCredential.user;
} catch (error) {
console.error('Sign in error:', error.message);
throw error;
}
}Firebase Email/Password Auth Documentation
Allow users to sign in with their GitHub accounts. Useful for developer-focused applications.
Setup Steps
- Create GitHub OAuth App
Go to GitHub Developer Settings → OAuth Apps → New OAuth App
- Configure OAuth App
Set the callback URL to:
https://[PROJECT-ID].firebaseapp.com/__/auth/handler - Get Client ID and Secret
Copy the Client ID and Client Secret from GitHub
- Enable in Firebase
Go to Firebase Console → Authentication → Sign-in method → GitHub
- Enter Credentials
Paste the Client ID and Client Secret from GitHub
import { getAuth, signInWithPopup, GithubAuthProvider } from 'firebase/auth';
const auth = getAuth();
const provider = new GithubAuthProvider();
// Request additional scopes if needed
provider.addScope('user:email');
async function signInWithGitHub() {
try {
const result = await signInWithPopup(auth, provider);
const user = result.user;
// Get GitHub access token for API calls if needed
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential?.accessToken;
return { user, token };
} catch (error) {
console.error('GitHub sign-in error:', error);
throw error;
}
}Firebase GitHub Auth Documentation
Let users try your app without creating an account. Later, they can link their anonymous account to a permanent one.
import { getAuth, signInAnonymously } from 'firebase/auth';
const auth = getAuth();
async function signInAnon() {
try {
const result = await signInAnonymously(auth);
// User is signed in anonymously
// result.user.isAnonymous === true
return result.user;
} catch (error) {
console.error('Anonymous sign-in error:', error);
throw error;
}
}Firebase Anonymous Auth Documentation
Users can link multiple authentication methods to the same account. This allows them to sign in with any linked provider.
import { linkWithPopup, GoogleAuthProvider } from 'firebase/auth';
const auth = getAuth();
// Link Google to existing account
async function linkGoogleAccount() {
const user = auth.currentUser;
if (!user) throw new Error('No user signed in');
const provider = new GoogleAuthProvider();
try {
const result = await linkWithPopup(user, provider);
console.log('Account linked successfully');
return result.user;
} catch (error) {
if (error.code === 'auth/credential-already-in-use') {
// Handle: Google account already linked to another user
}
throw error;
}
}