Skip to content

[FirebaseAuth]: flutter Only on web platform exception at FirebaseAuth.instance #13475

Closed
@wakhilji

Description

@wakhilji

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Auth

Which platforms are affected?

Web

Description

When I use the FirebaseAuth.instance I get the following exception, only on web unfortunately, everything works fine on Andriod.

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).

I have tried many thing, not sure what to do after spending 2 hours on this. Please help.

Reproducing the issue

This is how my main.dart looks like
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

import 'app.dart';
import 'data/repositories/authentication/authentication_repository.dart';
import 'firebase_options.dart';

Future main() async {
// Ensure that the WidgetsBinding has been initialized before calling Firebase.initializeApp
final WidgetsBinding widgetsBinding =
WidgetsFlutterBinding.ensureInitialized();
// Initialize GetStorage to store data locally
await GetStorage.init();
// Await SplashScreen until other services are initialized
if (!kIsWeb) FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
// Initialize Firebase with the default options and the current platform configuration (Android, iOS, web, etc.)
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
name: 'App-Name',
).then((app) {
// Initialize Firestore with the FirebaseApp instance
//Get.put(FirebaseFirestore.instanceFor(app: app));
// Initialize the Firebase Authentication with the FirebaseApp instance
//Get.put(FirebaseAuth.instanceFor(app: app));
// Then initialize the AuthenticationRepository with the FirebaseApp instance
Get.put(AuthenticationRepository());
});

runApp(const MainApp());
}

I am calling the final _auth = FirebaseAuth.instance; in AuthenticationRepository.

Firebase Core version

3.6.0

Flutter Version

3.5.2

Relevant Log Output

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).
https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js 2220:29                          getApp
packages/firebase_core_web/src/interop/core.dart 59:28                                      app$
packages/firebase_core_web/src/firebase_core_web.dart 360:48                                <fn>
packages/firebase_core_web/src/firebase_core_web.dart 384:21                                guardNotInitialized
packages/firebase_core_web/src/firebase_core_web.dart 360:13                                app
packages/firebase_core/src/firebase.dart 79:41                                              app
packages/firebase_auth/src/firebase_auth.dart 38:47                                         get instance
packages/sidrm_store/data/repositories/authentication/authentication_repository.dart 15:30  new
packages/sidrm_store/main.dart 30:13                                                        <fn>
dart-sdk/lib/async/zone.dart 1661:54                                                        runUnary
dart-sdk/lib/async/future_impl.dart 163:18                                                  handleValue
dart-sdk/lib/async/future_impl.dart 861:44                                                  handleValueCallback
dart-sdk/lib/async/future_impl.dart 890:13                                                  _propagateToListeners
dart-sdk/lib/async/future_impl.dart 666:5                                                   [_completeWithValue]

Flutter dependencies

Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.

Additional context and comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs AttentionThis issue needs maintainer attention.platform: webIssues / PRs which are specifically for web.plugin: authresolution: userThis was a user issue, e.g. invalid configuration or code.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions