오류 처리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Firebase 인증 SDK는 인증 방법을 사용하여 발생할 수 있는 다양한 오류를 포착하는 간단한 방법을 제공합니다. Flutter용 SDK는 FirebaseAuthException
클래스를 통해 이러한 오류를 노출합니다.
최소한 code
및 message
가 제공되지만 경우에 따라 이메일 주소 및 사용자 인증 정보와 같은 추가 속성도 제공됩니다. 예를 들어 사용자가 이메일과 비밀번호로 로그인하려고 하면 발생하는 오류를 명시적으로 포착할 수 있습니다.
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: "barry.allen@example.com",
password: "SuperSecretPassword!"
);
} on FirebaseAuthException catch (e) {
print('Failed with error code: ${e.code}');
print(e.message);
}
각 방법은 인증 호출 유형에 따라 다양한 오류 코드와 메시지를 제공합니다. Reference API는 각 방법의 오류에 관한 최신 세부정보를 제공합니다.
too-many-requests
또는 operation-not-allowed
같은 다른 오류는 Firebase 인증 할당량에 도달하거나 특정 인증 제공업체를 사용 설정하지 않은 경우에 발생할 수 있습니다.
account-exists-with-different-credential
오류 처리
Firebase Console에서 이메일 주소당 계정 1개를 사용 설정한 경우 다른 Firebase 사용자의 제공업체(예: Facebook)에 이미 존재하는 이메일을 사용하여 Google과 같은 제공업체에 로그인을 시도하면 AuthCredential
클래스(Google ID 토큰)와 함께 auth/account-exists-with-different-credential
오류가 발생합니다.
원하는 제공업체로의 로그인 과정을 완료하려면 먼저 사용자가 기존 제공업체(예: Facebook)에 로그인한 후 신규 제공업체의 AuthCredential
(Google ID 토큰)에 연결해야 합니다.
FirebaseAuth auth = FirebaseAuth.instance;
// Create a credential from a Google Sign-in Request
var googleAuthCredential = GoogleAuthProvider.credential(accessToken: 'xxxx');
try {
// Attempt to sign in the user in with Google
await auth.signInWithCredential(googleAuthCredential);
} on FirebaseAuthException catch (e) {
if (e.code == 'account-exists-with-different-credential') {
// The account already exists with a different credential
String email = e.email;
AuthCredential pendingCredential = e.credential;
// Fetch a list of what sign-in methods exist for the conflicting user
List<String> userSignInMethods = await auth.fetchSignInMethodsForEmail(email);
// If the user has several sign-in methods,
// the first method in the list will be the "recommended" method to use.
if (userSignInMethods.first == 'password') {
// Prompt the user to enter their password
String password = '...';
// Sign the user in to their account with the password
UserCredential userCredential = await auth.signInWithEmailAndPassword(
email: email,
password: password,
);
// Link the pending credential with the existing account
await userCredential.user.linkWithCredential(pendingCredential);
// Success! Go back to your application flow
return goToApplication();
}
// Since other providers are now external, you must now sign the user in with another
// auth provider, such as Facebook.
if (userSignInMethods.first == 'facebook.com') {
// Create a new Facebook credential
String accessToken = await triggerFacebookAuthentication();
var facebookAuthCredential = FacebookAuthProvider.credential(accessToken);
// Sign the user in with the credential
UserCredential userCredential = await auth.signInWithCredential(facebookAuthCredential);
// Link the pending credential with the existing account
await userCredential.user.linkWithCredential(pendingCredential);
// Success! Go back to your application flow
return goToApplication();
}
// Handle other OAuth providers...
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-04(UTC)
[null,null,["최종 업데이트: 2025-08-04(UTC)"],[],[],null,["\u003cbr /\u003e\n\nThe Firebase Authentication SDKs provide a simple way for catching the various errors which may occur which using\nauthentication methods. The SDKs for Flutter expose these errors via the `FirebaseAuthException`\nclass.\n\nAt a minimum, a `code` and `message` are provided, however in some cases additional properties such as an email address\nand credential are also provided. For example, if the user is attempting to sign in with an email and password,\nany errors thrown can be explicitly caught: \n\n try {\n await FirebaseAuth.instance.signInWithEmailAndPassword(\n email: \"barry.allen@example.com\",\n password: \"SuperSecretPassword!\"\n );\n } on FirebaseAuthException catch (e) {\n print('Failed with error code: ${e.code}');\n print(e.message);\n }\n\nEach method provides various error codes and messages depending on the type of authentication invocation type. The\n[Reference API](https://pub.dev/documentation/firebase_auth/latest/) provides up-to-date details on the errors for each method.\n\nOther errors such as `too-many-requests` or `operation-not-allowed` may be thrown if you reach the Firebase Authentication quota,\nor have not enabled a specific auth provider.\n\nHandling `account-exists-with-different-credential` Errors\n\nIf you enabled the One account per email address setting in the [Firebase console](https://console.firebase.google.com/project/_/authentication/providers),\nwhen a user tries to sign in a to a provider (such as Google) with an email that already exists for another Firebase user's provider\n(such as Facebook), the error `auth/account-exists-with-different-credential` is thrown along with an `AuthCredential` class (Google ID token).\nTo complete the sign-in flow to the intended provider, the user has to first sign in to the existing provider (e.g. Facebook) and then link to the former\n`AuthCredential` (Google ID token). \n\n FirebaseAuth auth = FirebaseAuth.instance;\n\n // Create a credential from a Google Sign-in Request\n var googleAuthCredential = GoogleAuthProvider.credential(accessToken: 'xxxx');\n\n try {\n // Attempt to sign in the user in with Google\n await auth.signInWithCredential(googleAuthCredential);\n } on FirebaseAuthException catch (e) {\n if (e.code == 'account-exists-with-different-credential') {\n // The account already exists with a different credential\n String email = e.email;\n AuthCredential pendingCredential = e.credential;\n\n // Fetch a list of what sign-in methods exist for the conflicting user\n List\u003cString\u003e userSignInMethods = await auth.fetchSignInMethodsForEmail(email);\n\n // If the user has several sign-in methods,\n // the first method in the list will be the \"recommended\" method to use.\n if (userSignInMethods.first == 'password') {\n // Prompt the user to enter their password\n String password = '...';\n\n // Sign the user in to their account with the password\n UserCredential userCredential = await auth.signInWithEmailAndPassword(\n email: email,\n password: password,\n );\n\n // Link the pending credential with the existing account\n await userCredential.user.linkWithCredential(pendingCredential);\n\n // Success! Go back to your application flow\n return goToApplication();\n }\n\n // Since other providers are now external, you must now sign the user in with another\n // auth provider, such as Facebook.\n if (userSignInMethods.first == 'facebook.com') {\n // Create a new Facebook credential\n String accessToken = await triggerFacebookAuthentication();\n var facebookAuthCredential = FacebookAuthProvider.credential(accessToken);\n\n // Sign the user in with the credential\n UserCredential userCredential = await auth.signInWithCredential(facebookAuthCredential);\n\n // Link the pending credential with the existing account\n await userCredential.user.linkWithCredential(pendingCredential);\n\n // Success! Go back to your application flow\n return goToApplication();\n }\n\n // Handle other OAuth providers...\n }\n }"]]