firebase-auth
Skill669 starsChanged 3 months agoMITView on GitHub
Use when setting up auth, managing auth state, implementing email/password or social sign-in, handling auth errors, or managing users.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- DentVega/firebase-agent-skillstheir own version, first seen Oct 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- DentVega/firebase-agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository36 other files it gives its agents.
- AGENTS.mdAGENTS.md
- accessibilitySkill
- architecture-feature-firstSkill
- blocSkill
- code-reviewSkill
- dart-3-updatesSkill
- developing-genkit-dartSkill
- effective-dartSkill
- firebase-aiSkill
- firebase-analyticsSkill
- firebase-app-checkSkill
- firebase-cloud-firestoreSkill
- firebase-cloud-functionsSkill
- firebase-crashlyticsSkill
- firebase-databaseSkill
- firebase-data-connectSkill
- firebase-in-app-messagingSkill
- firebase-messagingSkill
- firebase-remote-configSkill
- firebase-storageSkill
- flutter-app-architectureSkill
- flutter-best-practicesSkill
- flutter-change-notifierSkill
- flutter-errorsSkill
- flutterfire-configureSkill
- flutter-pre-cachingSkill
- flutter-use-column-row-firstSkill
- generate-images-with-firebase-aiSkill
- inclusive-designSkill
- mockitoSkill
- mocktailSkill
- patrol-e2e-testingSkill
- providerSkill
- revenuecat-testingSkill
- riverpodSkill
- testingSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 10 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Use this skill when:
- Distinctive: line 52
Use the appropriate stream based on what you need to observe:
- Distinctive: line 130
Verify the user's email address after account creation.
- Very specific: line 134
When email enumeration protection is enabled, sendPasswordResetEmail() may complete without an error even if the email is not registered.
- Distinctive: line 175
If a user signs in with a social provider after registering with the same email manually, Firebase's trusted provider concept will …
- Very specific: line 177
When signing in with Apple, add the email and name scopes to present the full first-time sign-in UI (including "Share/Hide email"):
- Very specific: line 185
Android: use revokeAccessToken() with the access token from userCredential.credential?.accessToken.
- Distinctive: line 204
Before using phone authentication, ensure platform-specific prerequisites are met:
- Distinctive: line 208
Web: Add your application's domain to the Firebase console under OAuth redirect domains.
- Very specific: line 218
If the SDK uses a Safari view controller-hosted challenge, handle the return URL using uni_links/app_links or application:openURL: in the …
- Very specific: line 224
Always use try-catch with FirebaseAuthException.
- Very specific: line 250
Use verifyBeforeUpdateEmail() — not updateEmail() — to change a user's email.
- Very specific: line 252
Use linkWithCredential() to connect multiple auth providers to a single account.
- Distinctive: line 253
Verify the user's identity before linking new credentials.
- Distinctive: line 259
Never store sensitive authentication credentials in client-side code.
- Very specific: line 262
Call FirebaseAuth.instance.signOut() when users exit the app.
- Distinctive: line 266
Use multi-factor authentication for sensitive applications.
- Distinctive: line 287
Use HTTPS URLs in production to prevent link interception.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Firebase Authentication Skill
This skill defines how to correctly use Firebase Authentication in Flutter applications.
When to Use
Use this skill when:
- Setting up Firebase Authentication in a Flutter project.
- Listening to authentication state changes.
- Implementing email/password, phone number, or social sign-in.
- Managing user profiles, account linking, or MFA.
- Handling authentication errors (including iOS
recaptcha-sdk-not-linkedfor phone auth). - Applying security best practices for auth flows.
1. Setup and Configuration
flutter pub add firebase_authimport 'package:firebase_auth/firebase_auth.dart';- Enable desired authentication providers in the Firebase console before using them.
- Initialize Firebase before using any Firebase Authentication features.
Local emulator for testing:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
// ...
}2. Authentication State Management
Use the appropriate stream based on what you need to observe:
| Stream | Fires when |
authStateChanges() | User signs in or out |
idTokenChanges() | ID token changes (including custom claims) |
userChanges() | User data changes (e.g., profile updates) |
FirebaseAuth.instance
.authStateChanges()
.listen((User? user) {
if (user == null) {
print('User is currently signed out!');
} else {
print('User is signed in!');
}
});- Listen to these streams immediately when the app starts to handle the initial auth state.
- Custom claims are only available after sign-in, re-authentication, token expiration, or manual token refresh.
3. Email and Password Authentication
Create a new account:
try {
final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: emailAddress,
password: password,
);
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
print('The account already exists for that email.');
}
} catch (e) {
print(e);
}Sign in:
try {
final credential = await FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailAddress,
password: password,
);
} on FirebaseAuthException catch (e) {
final String error = switch (e.code) {
'invalid-email' => 'The email address is not valid.',
// Email enumeration protection (default since Sep 2023) reports
// 'invalid-credential' instead of 'user-not-found' / 'wrong-password';
// older native SDKs report 'invalid-login-credentials'. Handle all four so
// the app works with the setting on or off.
'invalid-credential' ||
'invalid-login-credentials' ||
'user-not-found' ||
'wrong-password' =>
'The email address or password is incorrect.',
'user-disabled' => 'This account has been disabled.',
'too-many-requests' ||
'network-request-failed' =>
'Something went wrong. Try again later.',
// Always keep a default branch — codes differ by platform and SDK version
// (for example Windows reports 'unknown-error' for a wrong password).
_ => 'Sign-in failed (${e.code}).',
};
print(error);
}- Verify the user's email address after account creation.
- Firebase rate-limits new email/password sign-ups from the same IP to protect against abuse.
- On iOS/macOS, authentication state persists between app re-installs via the system keychain.
- Since September 2023, Firebase enables email enumeration protection by default on new projects, replacing
user-not-foundandwrong-passwordwithinvalid-credential. Manage this in the Firebase console under Authentication > Settings. - When email enumeration protection is enabled,
sendPasswordResetEmail()may complete without an error even if the email is not registered. Treat this as expected behavior and do not use password-reset responses to infer whether an email exists.
Share authentication state between Apple apps:
On Apple platforms, share auth state between apps in the same developer account by storing it in a shared Keychain access group. Enable the Keychain Sharing capability for each app with the same access group, then configure Firebase Auth with the fully qualified access group:
await FirebaseAuth.instance.setSettings(
userAccessGroup: 'TEAMID.com.example.group1',
);Switching from the default Keychain to a shared access group signs out the existing user unless migrated. Pass migrateCurrentUser: true (requires a non-null userAccessGroup) to preserve the current session, including an anonymous one — safe to call at app startup before any other Auth call, since it reads the existing session straight from the Keychain before Auth restores it. Migration can overwrite a user already stored in the destination access group.
4. Social Authentication
Google Sign-In (native platforms):
Future<UserCredential> signInWithGoogle() async {
final GoogleSignInAccount? googleUser = await GoogleSignIn.instance.authenticate();
final GoogleSignInAuthentication googleAuth = googleUser.authentication;
final credential = GoogleAuthProvider.credential(idToken: googleAuth.idToken);
return await FirebaseAuth.instance.signInWithCredential(credential);
}Google Sign-In (web):
Future<UserCredential> signInWithGoogle() async {
GoogleAuthProvider googleProvider = GoogleAuthProvider();
googleProvider.addScope('https://www.googleapis.com/auth/contacts.readonly');
googleProvider.setCustomParameters({'login_hint': 'user@example.com'});
return await FirebaseAuth.instance.signInWithPopup(googleProvider);
}- Configure platform-specific settings for each provider (e.g., SHA1 key for Google Sign-In on Android).
- If a user signs in with a social provider after registering with the same email manually, Firebase's trusted provider concept will automatically change their authentication provider.
- On Android,
signInWithProvideropens a Chrome Custom Tab. IfAndroidManifest.xmlcontainsandroid:taskAffinity=""(Flutter's default), the tab closes when the user switches apps (e.g., to use a password manager), causing aweb-context-already-presentederror. Removeandroid:taskAffinity=""to fix this. - When signing in with Apple, add the
emailandnamescopes to present the full first-time sign-in UI (including "Share/Hide email"):final appleProvider = AppleAuthProvider(); appleProvider.addScope('email'); appleProvider.addScope('name'); - To revoke Apple auth tokens after sign-in, use the appropriate API per platform:
- Apple platforms (iOS/macOS/web): use
revokeTokenWithAuthorizationCode()with the authorization code fromuserCredential.additionalUserInfo?.authorizationCode. - Android: use
revokeAccessToken()with the access token fromuserCredential.credential?.accessToken.
// Apple platforms (iOS/macOS/web) final authCode = userCredential.additionalUserInfo?.authorizationCode; if (authCode != null) { await FirebaseAuth.instance.revokeTokenWithAuthorizationCode(authCode); } // Android final accessToken = userCredential.credential?.accessToken; if (accessToken != null) { await FirebaseAuth.instance.revokeAccessToken(accessToken); } - Apple platforms (iOS/macOS/web): use
5. Phone Number Authentication
Before using phone authentication, ensure platform-specific prerequisites are met:
- Android: SHA-1 hashes must be configured in the Firebase console and Google Play Integrity API enabled.
- iOS: APNs authentication key must be configured with FCM and background modes for remote notifications enabled.
- Web: Add your application's domain to the Firebase console under OAuth redirect domains.
Phone number sign-in is only supported on real devices and the web. Testing on device emulators is not supported.
iOS: recaptcha-sdk-not-linked error
On iOS, verifyPhoneNumber can throw FirebaseAuthException with code recaptcha-sdk-not-linked when Identity Platform expects reCAPTCHA Enterprise but the native SDK is not linked. This cannot be resolved from Dart — fix it at the native iOS or GCP level:
- Recommended: Link the reCAPTCHA Enterprise iOS SDK in Xcode following Google's guide.
- Alternative: Disable reCAPTCHA SMS defense via the Identity Toolkit
projects.updateConfigREST API (setrecaptchaConfig.phoneEnforcementStatetoOFFandrecaptchaConfig.useSmsTollFraudProtectiontofalse). See the official steps. This reduces fraud protection — prefer linking the SDK. - If the SDK uses a Safari view controller-hosted challenge, handle the return URL using
uni_links/app_linksorapplication:openURL:in the iOS runner.
6. Error Handling
- Always use
try-catchwithFirebaseAuthException. - Branch on
e.code, never one.message— messages come from the native SDKs, differ between platforms, and change between SDK versions. - Codes differ between platforms for the same situation (e.g., Windows uses
unknown-error,no-signed-in-user,account-exists-with-different-credentials). Check the error code reference when targeting several platforms. - Catch
FirebaseAuthMultiFactorExceptionby type, beforeFirebaseAuthException, and complete sign-in withe.resolver; its code differs by platform (second-factor-requiredvsmulti-factor-auth-required). signInWithRedirect,getRedirectResultandreauthenticateWithPopupare the exception — they throw a plainFirebaseAuthExceptioncarrying the multi-factor code, without aresolver. Branch on the code in those flows, or enrolled users are stranded on a generic error with no way to complete the second factor.- On Android and Apple,
verifyPhoneNumberdoes not throw — errors arrive in theverificationFailedcallback. - Handle
account-exists-with-different-credentialby signing the user in with the provider their account already uses, then callinglinkWithCredential(e.credential). With email enumeration protection enabled, Firebase does not reveal which provider that is, so let the user choose. - Handle
too-many-requestswith retry logic or user feedback. - Handle
operation-not-allowedby ensuring the provider is enabled in the Firebase console. - On iOS,
recaptcha-sdk-not-linkedduringverifyPhoneNumberis raised by the native Firebase iOS Auth SDK and requires native setup or GCP configuration changes — it cannot be fixed from Dart code alone.
7. User Management
// Update profile
await FirebaseAuth.instance.currentUser?.updateProfile(
displayName: "Jane Q. User",
photoURL: "https://example.com/jane-q-user/profile.jpg",
);
// Update email (sends verification to new address first)
await user?.verifyBeforeUpdateEmail("newemail@example.com");- Use
verifyBeforeUpdateEmail()— notupdateEmail()— to change a user's email. The email only updates after the user verifies it. - Store only essential info in the auth profile; use a database for additional user data.
- Use
linkWithCredential()to connect multiple auth providers to a single account. - Verify the user's identity before linking new credentials.
8. Security Best Practices
- Never store sensitive authentication credentials in client-side code.
- Monitor auth state changes for proper session management.
- Validate user input before submitting authentication requests to prevent injection attacks.
- Call
FirebaseAuth.instance.signOut()when users exit the app. - For sensitive operations, re-authenticate users with
reauthenticateWithCredential(). - Enforce strong password policies for email/password auth.
- In Realtime Database and Cloud Storage Security Rules, use the
authvariable to get the signed-in user's UID for access control. - Use multi-factor authentication for sensitive applications.
9. Multi-Factor Authentication
Security warning: Avoid SMS-based MFA. SMS is insecure and easy to compromise or spoof.
Platform limitation: Windows does not support MFA. MFA with multiple tenants is not supported on Flutter.
- Enable at least one MFA-compatible provider before implementing MFA.
10. Email Link Authentication
Important: Firebase Dynamic Links is deprecated for email link authentication. Firebase Hosting is now used to send sign-in links.
- Set
handleCodeInApp: trueinActionCodeSettings— sign-in must always be completed in the app. - Store the user's email locally (e.g.,
SharedPreferences) when sending the sign-in link. - Never pass the user's email in redirect URL parameters — this enables session injection attacks.
- Use HTTPS URLs in production to prevent link interception.
- Configure the app to detect incoming links and parse the underlying deep link for sign-in completion.
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

