• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    Dart
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A dart-native implementation of the Firebase Auth and Firestore SDKs

Note: Development on this package is currently on hold. You're welcome to use it but be aware that there will be no support or ongoing updates for the time being.

firedart 🔥🎯

pub package

A dart-native implementation of the Firebase Auth and Firestore SDKs.

This library attempts to minimize dependencies with the intention of making it able to run in any environment capable of executing dart code. Currently it has been successfully tested using the dart runtime (x86-64 and arm32) as well as on Flutter Android, iOS and Desktop.

Firedart currently implements a subset of Firebase Auth and Firestore.

Dependencies

Add firedart to your pubspec.yaml file:

dependencies:
  firedart: [latest version]

Firebase Auth

The FirebaseAuth class implements the necessary functionality for managing accounts. It currently only supports Email/Password sign-in and anonymous sign-in, so make sure these are enabled under Authentication -> Sign-in Method.

You'll also need to go to your Firebase Console, open Project Settings and under the General tab copy the Web API Key.

Note: in order to reduce external dependencies this library doesn't include a mechanism for persisting tokens. Please look at the following examples based on SharedPreferences and Hive.

Usage

import 'package:firedart/firedart.dart';

FirebaseAuth has a singleton version which should be enough for most use cases. You'll need to initialise it with your API key and a token store (see note above):

FirebaseAuth.initialize(apiKey, await HiveStore.create());
await FirebaseAuth.instance.signIn(email, password);
var user = await FirebaseAuth.instance.getUser();

Alternatively you can instantiate your own FirebaseAuth object:

var firebaseAuth = FirebaseAuth.(apiKey, await PreferencesStore());
await firebaseAuth.signIn(email, password);
var user = await firebaseAuth.getUser();

Further usage examples can be found in the integration tests.

Limitations

  • Currently the only supported authentication provider is Email/Password.

Firestore

The Firestore class is a basic implementation of the service's RPC interface. The API is similar (but not identical) to that of the official SDK.

Usage

import 'package:firedart/firedart.dart';

As with FirebaseAuth, Firestore offers a singleton version that needs to be initialised with your Project ID, which you can find under Project Settings -> General:

Firestore.initialize(projectId);
var map = await Firestore.instance.collection("users").get();
var users = UserCollection.fromMap(map);

You can also instantiate your own Firestore object. Please note that if your database requires authenticated access, you'll need to pass along an instance of FirebaseAuth.

var firebaseAuth = FirebaseAuth.(apiKey, await HiveStore());
var auth = TokenAuthenticator.from(auth)?.authenticate;
var firestore = Firestore(projectId, authenticator: firebaseAuth);

await firebaseAuth.signIn(email, password);
var map = await firestore.collection("users").get();
var users = UserCollection.fromMap(map);

Further usage examples can be found in the integration tests.

Limitations

  • Collection queries (limit, sort, etc.) are currently not supported.
  • The data is not cached locally.
  • Failed writes (e.g. due to network errors) are not retried.
  • Closed streams are not automatically recovered.

Regenerating the RPC stubs

The Firestore RPC stubs are based on Google's official protobuf definition files from googleapis.

To regenerate them, you will need to check out both googleapis and protobuf.

Set the PROTOBUF and GOOGLEAPIS environment variables to point to your clones of the above repositories respectively, and then run:

$ tool/regenerate.sh

Debugging

For debugging Firebase Auth you can use VerboseClient, an HTTP client that logs all communication to the console. The logs can expose sensitive data including passwords and keys, so it's recommended to only enable it for development builds. In Flutter this can be achieved using the kReleaseMode constant from the foundation package:

var client = !kReleaseMode ? VerboseClient() : http.Client();
var firebaseAuth = FirebaseAuth(apiKey, await PreferencesStore(), httpClient: client);

Securing Tokens

If you're running your code in an environment that requires securing access tokens, you can extend TokenStore to persist data in a secure maner, e.g. by encrypting the data or storing it in an external vault. Example implementations can be found in token_store.dart.

More Repositories

1

ExpandableLayout

An expandable layout container for Android
Java
2,305
star
2

crdt

Dart implementation of Conflict-free Replicated Data Types (CRDTs)
Dart
137
star
3

AerialDream

A screensaver for Android inspired on the one from the Apple TV
Java
112
star
4

tudo

A simple to-do app
JavaScript
66
star
5

sql_crdt

Dart implementation of Conflict-free Replicated Data Types (CRDTs) using SQL databases
Dart
48
star
6

sqlite_crdt

Dart implementation of Conflict-free Replicated Data Types (CRDTs) using Sqlite
Dart
26
star
7

RemoteGallery

Access your SSH-hosted pictures remotely from your Android device
Java
18
star
8

hive_crdt

A CRDT backed by a Hive store
Dart
16
star
9

BottomNavigation

An implementation of the Material Design Bottom Navigation Drawer for Android
Java
15
star
10

crdt_sync

A dart-native turnkey solution for painless network synchronization
Dart
11
star
11

tudo_server

A simple to-do app server
Dart
10
star
12

crdt_draw

A collaborative real-time local-first global canvas
Dart
10
star
13

postgres_crdt

Dart implementation of Conflict-free Replicated Data Types (CRDTs) using PostgreSQL
Dart
10
star
14

SAM-Java

An example of the SAM (State-Action-Model) pattern in Java/Android
Java
7
star
15

ottobot

A Mattermost bot
Dart
6
star
16

BusinessTime

Simple work time counter, designed for automation
Java
6
star
17

crdt_server

Generic REST server based on Conflict-free Replicated Data Types (CRDTs)
Dart
5
star
18

tonie_shuffle

A command-line utility to shuffle Creative Tonie playlists
Dart
4
star
19

mattermost_dart

A basic implementation of the Mattermost API in dart
Dart
4
star
20

fireutil

Utility to manage Firestore databases
Dart
3
star
21

Protium-Demo

A demonstration of the Protium architecture
Java
2
star