Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
wakhilji opened this issue Oct 8, 2024 · 1 comment
Open
1 task done
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: web Issues / PRs which are specifically for web. plugin: auth type: bug Something isn't working

Comments

@wakhilji
Copy link

wakhilji commented Oct 8, 2024

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

@wakhilji wakhilji added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Oct 8, 2024
@SelaseKay SelaseKay added plugin: auth platform: web Issues / PRs which are specifically for web. labels Oct 8, 2024
@SelaseKay
Copy link
Contributor

Hi @wakhilji , I'm unable to reproduce this issue. Can you ensure you're not invoking FirebaseAuth.instance before initialisation?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: web Issues / PRs which are specifically for web. plugin: auth type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants