Question: Firebase Authentication Error – "auth/invalid-credential" or "auth/internal-error" after successful sign-in

clock icon

asked 65 days ago

message icon

1 Answers

eye icon

32 Views

I’m working on a web app using Firebase Authentication (v9 modular SDK) with Google Sign-In. The login flow works fine locally, but when I deploy it (for example, to Vercel or Firebase Hosting), I get the following error in the console after trying to sign in:

FirebaseError: Firebase: Error (auth/invalid-credential).

or sometimes:

FirebaseError: Firebase: Error (auth/internal-error).

Even though the Google sign-in popup appears and I select my account, the authentication doesn’t complete, and Firebase doesn’t return the user object.

I’ve already checked:

  • The Firebase project credentials are correct.
  • The web app has the correct API key and authDomain in the config.
  • The OAuth redirect domain is added in Firebase Console → Authentication → Sign-in method.

Still, the issue persists only on the deployed version (not locally).

What could be causing this issue, and how can I fix it?

1 Answers

Troubleshooting Firebase Authentication Error – "auth/invalid-credential" or "auth/internal-error"

Possible Causes & Solutions

Given that your application works locally but encounters errors when deployed, several factors could be contributing to the authentication issues, specifically the "auth/invalid-credential" and "auth/internal-error". Here are steps to diagnose and potentially resolve these issues:

  1. Check Firebase Console Configuration

    • Ensure that the OAuth consent screen settings in Google Cloud Console are correctly configured. This includes verifying the scope of the application and the test users if the app is still in a testing phase.
    • Validate that the Firebase project and the associated Google Cloud project are correctly linked.
  2. Verify Domain Configuration

    • Double-check if the correct domains are listed under the Authorized domains in Firebase Console→Authentication→Sign-in method.
    • If you've recently added new domains or changed any configurations, remember that it might take some time to propagate these changes.
  3. Examine Environment Variables

    • Confirm that the correct API keys and project identifiers are used in your production environment. Sometimes, different environments might mistakenly use different configurations.
    • Ensure no discrepancies between your local .env files and environment variables set in the deployment service (e.g., Vercel or Firebase Hosting).
  4. Inspect Redirect URLs

    • Make sure that the redirect URLs for OAuth are correctly formatted and match those specified in both the Firebase and Google Cloud Console settings.
  5. Review Dependencies

    • Verify that all dependencies are up-to-date, particularly those related to Firebase and any SDKs. Occasionally, outdated libraries can cause unforeseen issues.
  6. Check Browser Console and Network Logs

    • Look into the browser console and network logs for any additional error messages or failed network requests during the sign-in process. This could provide more context on what might be going wrong.
  7. Cross-Origin Resource Sharing (CORS) Issues

    • Check for CORS issues, as misconfigured CORS policies can also lead to failed authentication requests.
  8. Error Code Specific Checks

    • For "auth/invalid-credential": Make sure that all user credentials are managed correctly without any data corruption during the sign-in process.
    • For "auth/internal-error": This usually indicates an issue on the server side, like a configuration issue or a problem with Firebase services. Consider reaching out to Firebase support if the problem persists.

Next Steps

If these steps do not resolve the issue, consider creating a detailed bug report or support ticket with Firebase, including all relevant details like error messages, configuration settings, and what you have already tried. Sometimes, issues might be related to the Firebase platform itself.

Write your answer here

Top Questions