How to fix auth/user-cancelled in Firebase
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.
Quick fix
Fixes auth/user-cancelled
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);
}
}- Catch the user-cancelled error in your sign-in handler
- Display appropriate messaging for user cancellation
- Check for related cancellation error codes
- Test on different platforms and browsers
try {const result = await signInWithPopup(auth, googleProvider);// Handle successful sign-in} catch (error) {if (error.code === "auth/user-cancelled") {// User cancelled the operation - handle gracefullyconsole.log("Sign-in cancelled by user");} else {// Handle other authentication errorsconsole.error("Sign-in failed:", error.message);}}auth/user-cancelled
What this error means
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.
Typical symptoms
- FirebaseError with code "auth/user-cancelled" appears in the console
- Promise rejection occurs without the user successfully completing sign-in
- User is returned to the previous screen unexpectedly
- Alarmist error messages are displayed when user simply closes a dialog
Common causes
- User closes or dismisses a pop-up authentication window before completing sign-in
- User navigates away during a redirect-based OAuth flow
- User taps "Cancel" or "Back" on an authentication dialog or modal
- Browser blocks a pop-up window before it fully loads
- Another conflicting authentication popup was opened simultaneously
How to fix "auth/user-cancelled"
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.
Advanced notes
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.
Frequently asked questions
- What does "auth/user-cancelled" mean?
- 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.
- How do I fix "auth/user-cancelled"?
- 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.
- What causes "auth/user-cancelled"?
- User closes or dismisses a pop-up authentication window before completing sign-in User navigates away during a redirect-based OAuth flow User taps "Cancel" or "Back" on an authentication dialog or modal
- Is the "auth/user-cancelled" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Firebase Official Documentation
- ๐github.com - 5253(GitHub)
- ๐firebase.google.com - manage users(Official Docs)
- ๐github.com - 512(GitHub)
- ๐github.com - 1404(GitHub)