The auth/user-cancelled error occurs when a user dismisses or cancels a Firebase authentication flow, such as closing a sign-in popup or navigation dialog. While this is intentional user behavior, it needs proper error handling to avoid confusing users with unexpected error messages.
The "auth/user-cancelled" error is thrown by Firebase Authentication when a user deliberately cancels an authentication operation before it completes. This commonly happens when: 1. A sign-in popup is dismissed before the user finalizes authentication 2. A redirect-based OAuth flow is closed by the user 3. A phone authentication dialog is canceled during verification 4. A user presses "back" or taps outside a modal authentication interface Unlike other authentication errors that indicate technical problems, this error represents an intentional user action to abandon the sign-in process.
Wrap your Firebase authentication calls in a try-catch block to handle the cancellation gracefully:
try {
const result = await signInWithPopup(auth, googleProvider);
// Handle successful sign-in
} catch (error) {
if (error.code === "auth/user-cancelled") {
// User cancelled the operation - handle gracefully
console.log("Sign-in cancelled by user");
} else {
// Handle other authentication errors
console.error("Sign-in failed:", error.message);
}
}Avoid showing alarming error messages for user cancellation. Instead, provide neutral feedback:
if (error.code === "auth/user-cancelled") {
// Optional: Show a subtle message or simply return to login
setMessage("Sign-in cancelled");
// Or silently return without showing an error
} else {
setError(`Sign-in failed: ${error.message}`);
}Firebase may throw similar but distinct error codes depending on the platform and method:
- auth/popup-closed-by-user: User closed the popup window
- auth/cancelled-popup-request: Another popup was opened before this one completed
- auth/redirect-cancelled-by-user: OAuth redirect was cancelled
Handle all of these the same way as auth/user-cancelled:
The user-cancelled error may behave differently across platforms:
- Web (Chrome, Firefox, Safari): Most common with popup-based sign-in
- iOS: May occur after dismissing a modal or pressing back
- Android: Common when user closes a dialog or navigates away
Test your error handling in each target environment to ensure graceful fallback behavior.
For FirebaseUI implementations, handle cancellation using built-in callbacks. FirebaseUI-Web provides an onSignInCancelled callback, and FirebaseUI-Android exposes AuthException.AuthCancelledException. On iOS with Phone Authentication, ensure you handle cancellation after captcha verification completes.
Note that "auth/user-cancelled" does not appear in official Firebase error documentation, making it easy to miss. Always check the error code attribute (error.code) rather than relying on error messages, as messages may vary by platform and language.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage