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

Firebase web default initialization through dart code #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ Update `/web/index.html` in the body tag.
</script>
```

As an alternative, you can avoid the`<script>` item with the `firebaseConfig` configuration by initializing the `FbApp` instance in your app as it is done in the plugin example `main.dart` file.

```dart
final _app = FbApp(
apiKey: "API_KEY",
authDomain: "AUTH_DOMAIN",
databaseURL: "DATABASE_URL",
projectId: "PROJECT_ID",
storageBucket: "STORAGE_BUCKET",
messagingSenderId: "MESSAGING_SENDER_ID",
appId: "APP_ID",
measurementId: "MEASUREMENT_ID"
);
```
If the `<script>` item is present, it takes precedence over the initialization of the `FbApp` instance in dart code.

Follow Installation Instructions for Mobile: https://pub.dev/packages/firebase_auth

- Update `ios/Runner` and add the `GoogleService-Info.plist` downloaded from firebase
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<AuthBloc>(builder: (_) => _auth),
BlocProvider<AuthBloc>(create: (_) => _auth),
],
child: MaterialApp(
home: AuthCheck(),
Expand Down
4 changes: 2 additions & 2 deletions example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-storage.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-functions.js"></script>

<script>
<!-- <script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "API_KEY",
Expand All @@ -31,7 +31,7 @@
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
</script> -->
</body>

</html>
18 changes: 16 additions & 2 deletions lib/data/services/auth/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@ import 'impl.dart';

class FBAuth implements FBAuthImpl {
final FbApp app;
final _auth = auth();
Auth _auth;

FBAuth(this.app);
FBAuth(this.app) {
if (apps.isEmpty) {
initializeApp(
apiKey: this.app.apiKey,
authDomain: this.app.authDomain,
databaseURL: this.app.databaseURL,
projectId: this.app.projectId,
storageBucket: this.app.storageBucket,
messagingSenderId: this.app.messagingSenderId,
appId: this.app.appId,
measurementId: this.app.measurementId
);
}
_auth = auth();
}

Future _setPersistenceWeb(Auth _auth) async {
// try {
Expand Down