Firebase Authentication, how to add email, Google, Apple and SMS login
Email, Google, Apple and SMS sign-in with Firebase Authentication, with minimal code, real prices, rate limits and the redirect and SMS pitfalls.

- 1.What Firebase Authentication is
- 2.How much it costs
- 3.Setting up the project
- 4.Email and password
- 5.Signing in with Google
- 6.Signing in with Apple
- 7.Phone and SMS
- 8.Redirects and third-party cookies
- 9.The security that stays with you
- 10.When you need Identity Platform
- 11.Which method to pick
- 12.Frequently Asked Questions (FAQ)
- 13.Rate this article
- 14.Related Articles
- 15.Looking for a Software Engineer?
A hand-rolled login costs more than it looks. You need password hashing, confirmation emails, resets, a cap on attempts, tokens to refresh; every external provider then adds a different protocol to study. Firebase Authentication moves all of that onto Google's servers. The app calls the SDK, gets back a user with a token, and the service handles the rest.
This guide walks through the four most common web sign-ins (email with password, Google, Apple, SMS) with the minimal code for each. Then it covers what guides usually skip: the real prices, the hourly and daily limits, the third-party cookie problem with redirects, the risks of SMS. The data comes from the official Firebase documentation and the Identity Platform pricing page, both read on December 6, 2026.
All you need is a Google account to create the project from the Firebase console. Email and Google are free up to 50,000 monthly active users, and the same goes for Apple. To send real SMS messages you have to attach a payment method and move to the Blaze plan.
What Firebase Authentication is
It's Google's identity service for web and mobile apps. There are SDKs for web, Android, iOS, Flutter, Unity and C++, a ready-made login screen (FirebaseUI) and a backend that keeps the accounts. After sign-in the SDK gets an ID token, a JWT signed by Google and valid for one hour, which the SDK renews on its own. The app sends it to its own server or to other Firebase products, such as Firestore or Cloud Storage, where security rules read the user's identity.
One detail worth knowing right away. Firebase Authentication and Identity Platform are the same engine. The first is the entrance inside the Firebase console. The second is the version with the enterprise features (multi-factor authentication, SAML, OIDC, blocking functions), reached through an upgrade from the same console; I'll come back to it below.
How much it costs
Tier 1 providers (email, phone, anonymous sign-in, social logins like Google and Apple) are free up to 50,000 monthly active users (MAU), meaning accounts that signed in during the month. Past the threshold the cost is tiered: $0.0055 per user from 50,000 to 100,000, $0.0046 up to one million, $0.0032 up to ten million, $0.0025 beyond. An app with 60,000 active users therefore pays, by the numbers, $55 a month, because the first 50,000 don't count. Inactive users stay stored at no cost.
Tier 2 providers, OIDC and SAML, start at 50 free users per project; after that they cost $0.015 per user.
The line item that surprises people is SMS. Phone authentication and second-factor SMS are billed per message sent, not per user. The price varies a lot from country to country. The first ten SMS a day are not billed. From the pricing page, a few examples.
| Country | Dollars per SMS | Cost of 10,000 SMS (dollars) |
|---|---|---|
| United States, Turkey | 0.01 | 100 |
| Spain, United Kingdom | 0.04 | 400 |
| Italy | 0.05 | 500 |
| France, India | 0.07 | 700 |
| Germany, Netherlands | 0.09 | 900 |
| Russia | 0.32 | 3,200 |
| Indonesia | 0.35 | 3,500 |
The math is quick. The same volume of codes costs $100 to the United States and $3,500 to Indonesia. With 50,000 users on email or Google you pay nothing; ten thousand SMS to Italy come to $500 a month. That's why SMS is the last method to add, not the first.
Setting up the project
From the console you create the project, open Authentication and switch on each provider in the sign-in method tab. Two checks before writing code. The domain the app runs from must appear among the authorized domains (localhost is already there, but phone authentication doesn't accept it). And the web configuration needs an authDomain, for now the default one, project.firebaseapp.com; the reason becomes clear in the redirect section.
Once the package is installed (npm install firebase), initialization is the same for every method. The onAuthStateChanged observer is where the app finds out who the user is, even after a page reload.
import { initializeApp } from "firebase/app";
import { getAuth, onAuthStateChanged } from "firebase/auth";
const app = initializeApp({
apiKey: "...",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project",
appId: "..."
});
export const auth = getAuth(app);
onAuthStateChanged(auth, (user) => {
if (user) console.log("User:", user.uid);
else console.log("No user");
});
Official video from the Firebase channel, in English, on getting started with Firebase Authentication on the web
Email and password
It's the oldest method and the easiest to grasp. The user picks an email and a password, Firebase stores them (the password only as a hash) and returns an account. You have to enable the "Email/Password" provider in the console. Three calls cover registration and sign-in, a fourth handles password recovery.
import {
createUserWithEmailAndPassword, signInWithEmailAndPassword,
sendEmailVerification, sendPasswordResetEmail
} from "firebase/auth";
// sign-up
const cred = await createUserWithEmailAndPassword(auth, email, password);
await sendEmailVerification(cred.user);
// sign-in
await signInWithEmailAndPassword(auth, email, password);
// forgot password
await sendPasswordResetEmail(auth, email);
After registration the user is already logged in, but with an unverified email; confirmation comes from the link sent by sendEmailVerification. A few details are worth knowing before going live.
The password policy is set from the console: length from 6 to 30 characters (the default minimum is 6), requirements for uppercase, lowercase, numbers and symbols, with the choice between blocking weak passwords or only warning. On the client side the check is done with validatePassword. Email enumeration protection, which stops anyone from finding out which addresses are registered, is on by default in projects created since September 15, 2023.
The limits matter more than you'd think, especially on the free plan. Verification emails are capped at 1,000 a day, password reset emails at 150 a day, passwordless sign-in links at just 5 a day; on the Blaze plan they rise to 100,000, 10,000 and 25,000. Sign-ups are limited to 100 accounts an hour per IP address, a ceiling that an office or a live event can hit without noticing (from the console you can schedule a temporary increase).
Signing in with Google
Here the user doesn't create a password. They pick a Google account and Firebase handles the OAuth exchange. Once the provider is enabled, all you need is a GoogleAuthProvider object and a popup window.
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
const provider = new GoogleAuthProvider();
provider.setCustomParameters({ prompt: "select_account" });
try {
const result = await signInWithPopup(auth, provider);
console.log(result.user.displayName);
} catch (e) {
if (e.code === "auth/account-exists-with-different-credential") {
// same email already registered with another method
}
}
The error you'll hit sooner or later is auth/account-exists-with-different-credential. It shows up with the "one account per email address" setting, which is the default. If someone registered with email and password and then tries to enter with Google using the same address, Firebase refuses and asks you to link the two identities. Linking is done with linkWithCredential after the user authenticates with the original method. The interface has to plan for it, otherwise the user just sees an error.
The popup is handy on desktop, but the browser may block it and it's awkward on mobile. The alternative is signInWithRedirect, which sends the user to Google's page and then brings them back; the documentation recommends it for mobile. It has a cost, though, explained shortly.
Signing in with Apple
In code it's almost identical to Google, with OAuthProvider("apple.com") in place of the Google provider. The real work happens outside the code.
import { OAuthProvider, signInWithPopup } from "firebase/auth";
const provider = new OAuthProvider("apple.com");
provider.addScope("email");
provider.addScope("name");
const result = await signInWithPopup(auth, provider);
You need a paid Apple Developer Program account, because Sign in with Apple can only be configured there. From the Apple Developer site you register a Service ID, associate the website with the Return URL https://project.firebaseapp.com/__/auth/handler and create a private key for Sign in with Apple. In the Firebase console you enter the Service ID, Team ID, private key and key ID. If the app emails users (verification, reset), you also have to set up Apple's private email relay service, registering the address [email protected].
Then come the behaviors that catch people off guard. Apple doesn't provide the profile photo. The name is shared only at first sign-in, so it has to be saved right away, because it isn't sent again afterward. Users can choose to hide their email; in that case the app receives an address on the privaterelay.appleid.com domain. And anyone publishing the app on the App Store must plan for account deletion. The documentation asks you to reauthenticate the user, get the token and call revokeAccessToken before deleting the account.
A myth is going around on this topic: "if I offer Google login I have to offer Apple too." App Store Review Guideline 4.8 (Login Services) requires an alternative sign-in service with equivalent privacy requirements when the app uses a third-party login for the primary account. Sign in with Apple meets them and is the easiest route, not the only one. On the web the rule doesn't exist. It applies to those publishing apps in Apple's stores.
Phone and SMS
The user enters their number, receives a six-digit code, types it in. No password to remember, which is why the method is popular where SIM cards are more widespread than email, in India or Brazil for example. On the web it needs an anti-abuse reCAPTCHA check, which the SDK handles by itself; here it's hidden behind the sign-in button.
import { RecaptchaVerifier, signInWithPhoneNumber } from "firebase/auth";
window.recaptchaVerifier = new RecaptchaVerifier(auth, "sign-in-button", {
size: "invisible"
});
// phoneNumber in international format, with the country prefix
const confirmation = await signInWithPhoneNumber(
auth, phoneNumber, window.recaptchaVerifier
);
// when the user types in the 6-digit code they received
const result = await confirmation.confirm(code);
Before switching it on in production there are six things to know.
- The SMS region has to be enabled by hand. In new projects the default policy allows no country at all, so codes don't go out until you choose the markets you serve.
- In development you use test numbers, up to 10, with a six-digit code defined in the console. They cost nothing and don't send any SMS.
- Per IP address, verification requests are capped at 150 an hour and SMS sent at 50 a minute and 500 an hour.
- Per project the cap is 900 SMS a minute and 3,000 a day on Firebase Authentication; with the upgrade to Identity Platform the daily limit disappears.
- Google stores phone numbers to prevent spam, so the privacy notice to users has to say so, along with the fact that their carrier's charges may apply.
- An SMS code is not a strong factor, and I'll say it plainly. It can be intercepted or hijacked with a SIM swap; even carrier networks are in the crosshairs, as the case of SilentAir, where state-backed hackers read SMS messages and 2FA codes shows.
Then there's the financial risk, the most concrete one for whoever runs an app. There is a fraud called SMS pumping, in which a bot requests thousands of codes to high-rate numbers, which earn money on SMS termination, while the project pays the bill. The defenses available are the allowed-countries list, the per-IP limits already covered, a check on the ratio between SMS sent and SMS verified (the console shows it by region, and a success rate under 50% is a warning sign according to the documentation) and Firebase App Check. A feature still in beta, Phone Number Verification, tries to skip the SMS by leaning on the carrier; for now the documentation keeps it separate from the traditional flow.
Redirects and third-party cookies
This problem shows up in production more often than in testing. signInWithRedirect uses an iframe pointing to the Firebase Hosting domain, but browsers that block third-party storage don't allow it. The user comes back to the app and appears logged out, with no error at all. The block is already active in Firefox 109 and Safari 16.1; since June 24, 2024 it applies in Chrome too, from version 115. In local tests you almost never see it.
The official page on redirect best practices offers five routes, in order of simplicity.
- Set
authDomainto your own custom domain, addhttps://your-domain/__/auth/handlerto the OAuth provider's redirect URIs and redeploy. It's the right fix if the app runs on Firebase Hosting with its own domain. - Switch to
signInWithPopup, which returns the result directly. One line is enough, but popups can be blocked; on mobile they work worse. - Forward requests for
/__/auth/toproject.firebaseapp.comwith a reverse proxy (nginx, for example), transparently, without a 302 redirect; then apply the first fix. - Host the support files on your own domain, meaning the handler page, the iframe, the init.json file and the rest. It doesn't work with Apple and SAML and has to be kept up to date.
- Handle the provider login by hand and pass the credential to
signInWithCredential. It's the most complex.
If the app lives on a subdomain of firebaseapp.com you don't need to do anything. If it's elsewhere, I'd start with the first or the second and wouldn't touch the others without a specific reason.
The security that stays with you
Firebase keeps the passwords, but the app stays in your hands on four points.
The API key that appears in the web configuration is not a secret. The API keys documentation defines it as public per project. It identifies the project, it doesn't authorize anything. Hiding it, in practice, achieves nothing. What helps is restricting it (by domain or by app) and turning on App Check, which verifies that requests really come from your app.
Client-side identity isn't enough. An API or a server that trusts a uid sent by the browser is full of holes; the ID token has to be verified, with the Admin SDK, on every sensitive request.
import { getAuth } from "firebase-admin/auth";
const decoded = await getAuth().verifyIdToken(idToken);
const uid = decoded.uid;
Then the Firestore and Storage rules. Authenticated doesn't mean authorized. A rule that only requires a logged-in user gives every registered account access to everything. Rules have to be written, in short, around the uid of the data's owner.
Finally, the choice of factors. An SMS second factor, on top of the costs already seen, is the weakest of those available; for an app with sensitive data an authenticator app or a passkey makes more sense. By the way, in the table of contents of the official web documentation I read, passkeys don't appear as a method, so I don't take for granted that they switch on with two lines. To see where the question stands outside Firebase there's the guide on password managers, passkeys and 2FA and the analysis of the attacks on Google passkeys.
When you need Identity Platform
The upgrade from Firebase Authentication to Identity Platform is done from the console without changing the code you've already written. You need it in four cases: multi-factor authentication, sign-in with SAML or OIDC for enterprise customers, blocking functions (cloud functions that run before login or registration and can reject them, for example to block an email domain) and, as seen, the daily SMS cap. In return the costs become those on the Google Cloud pricing page. For a consumer app with email and Google it isn't needed; the temptation to do it "just to be safe" is an expense you can avoid.
Which method to pick
Starting from zero, here's what I'd do. Email and password plus Google, both free up to 50,000 monthly active users and with no hidden costs, cover the vast majority of cases. I add Apple when the app ships on iPhone with a third-party login, not before, because it requires the paid Developer account and a long setup. I keep SMS for markets where email isn't the main identity, with a closed list of countries and a budget alert active in the Google Cloud project. The rest, meaning MFA and SAML, arrives when a customer asks for it.
Anyone who'd rather start from a prompt than from code will find a different path, with Google's assistant, in the article on full-stack vibe coding in Google AI Studio. For the mobile interface, two useful reads are the comparison of React Native and Flutter and the guide to state management in Flutter.
One last test I recommend. Open the app in a private Safari window, sign in with Google, reload the page. If the user is still there, the redirect holds.
Frequently Asked Questions (FAQ)
1. Is Firebase Authentication free?
Yes, up to 50,000 monthly active users for email, social, phone and anonymous sign-in. Past the threshold you pay in tiers, starting at $0.0055 per user. SMS is always billed per message, apart from the first ten a day.
2. How much does a verification SMS cost?
It depends on the country. For Italy the pricing page lists $0.05 per SMS, for the United States $0.01, for Indonesia $0.35. A sent SMS is billed even if the user never types the code.
3. Is Apple sign-in mandatory?
No, an equivalent alternative service is mandatory for App Store apps with a third-party login (Guideline 4.8). Sign in with Apple is the simplest way to meet it. On the web it doesn't apply.
4. Why does the Google login get lost after the redirect?
Almost always because of third-party cookies. signInWithRedirect uses an iframe on another domain, which the major browsers block. The fix is authDomain on your own domain, or switching to signInWithPopup.
5. Should the Firebase API key be hidden?
No, it's public per project. It doesn't give access to data; the security rules and the user's token do that. It should be restricted by domain or app and protected with App Check.
Enjoyed the article?
Open the discussion on X
Related Articles

How to Connect an Epson Fiscal Printer to a Web Management System

How to Connect an RCH Fiscal Printer to a Web Management System

How to Connect a Custom Fiscal Printer to a Web Management System

What is a domain name and how to choose the right one, .com or .it

IDE vs CLI vs TUI vs ADE, how AI coding tools differ

Laravel for Java doesn't exist, but Rust and Go versions have arrived
Stay updated
🌐 3k readers worldwide, every SaturdaySubscribe to the newsletter to receive new articles directly in your inbox.
