fb_auth 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

Buy Me A Coffee Donate

fb_auth #

A Shared Firebase Auth Plugin for Mobile, Web and Desktop. Included AuthBloc for minimal setup! Single dynamic import and compile time ready for ios, android, macos, windows, linux and web.

Getting Started #

Setup your Bloc

final _auth = AuthBloc();

Follow Installation Instructions for Web: https://pub.dev/packages/firebase

Update /web/index.html in the body tag.

<!-- The core Firebase JS SDK is always required and must be listed first -->
  <script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js"></script>

  <!-- TODO: Add SDKs for Firebase products that you want to use
      https://firebase.google.com/docs/web/setup#config-web-app -->
  <script src="https://www.gstatic.com/firebasejs//6.3.3/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-firestore.js"></script>
  <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>
    // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: "API_KEY",
      authDomain: "AUTH_DOMAIN",
      databaseURL: "DATABASE_URL",
      projectId: "PROJECT_ID",
      storageBucket: "STORAGE_BUCKET",
      messagingSenderId: "MESSAGING_SENDER_ID",
      appId: "APP_ID"
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
  </script>

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

  • Update ios/Runner and add the GoogleService-Info.plist downloaded from firebase

  • Update android/app and add the google-services.json downloaded from firebase

  • Update android/build.gradle and update the classpath:

    classpath 'com.google.gms:google-services:4.2.0'

Actions #

  • Check Current User
_auth.dispatch(CheckUser());
  • Listen for Auth Changes
_userChanged = _fbAuth.onAuthChanged().listen((user) {
    _auth.dispatch(UpdateUser(user));
});
  • Logout
_auth.dispatch(LogoutEvent(_user));
  • Login
_auth.dispatch(LoginEvent(_email, _password));
  • Guest
_auth.dispatch(LoginGuest());
  • Create Account
_auth.dispatch(CreateAccount(_email, _password, displayName: _name));
  • Edit Info
_auth.dispatch(EditInfo(displayName: _name));
  • Forgot Password
_auth.dispatch(ForgotPassword(_email));
  • Send Email Verification
_auth.dispatch(SendEmailVerification());

1.1.1 #

  • Bumping Version

1.1.0 #

  • Updating to Bloc 2.0.0

1.0.6 #

  • Fixing Google Login (Mobile, Web)

1.0.3 #

  • Updating to bloc 1.0.0
  • Fixing Google Login (Mobile, Web)
  • Try login after failed create account or user is null

1.0.1 #

  • Support for Login with Access Token
  • Support for Google Sign In for Mobile and Web

1.0.0 #

  • Adding Support for Desktop
  • Updated Example for Desktop
  • Adding App Config Requirement
  • Fixing Bugs with io auth

0.0.2 #

  • Add Sign In As Guest

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:async';

import 'package:fb_auth/fb_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'plugins/desktop/desktop.dart';
import 'ui/auth/check.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  setTargetPlatformForDesktop();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  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",
  );

  AuthBloc _auth;
  StreamSubscription<AuthUser> _userChanged;

  @override
  void dispose() {
    _auth.close();
    _userChanged?.cancel();
    super.dispose();
  }

  @override
  void initState() {
    _auth = AuthBloc(saveUser: _saveUser, deleteUser: _deleteUser, app: _app);
    _auth.add(CheckUser());
    final _fbAuth = FBAuth(_app);
    _userChanged = _fbAuth.onAuthChanged().listen((user) {
      _auth.add(UpdateUser(user));
    });
    super.initState();
  }

  static _deleteUser() async {}

  static _saveUser(user) async {}

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider<AuthBloc>(builder: (_) => _auth),
      ],
      child: MaterialApp(
        home: AuthCheck(),
      ),
    );
  }
}

// class MyApp extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     return MaterialApp(
//       home: Scaffold(
//         appBar: AppBar(),
//       ),
//     );
//   }
// }

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fb_auth: ^1.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fb_auth/fb_auth.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
73
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-0.12 points)

225 out of 232 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/data/blocs/auth/auth_bloc.dart. (-0.50 points)

Analysis of lib/data/blocs/auth/auth_bloc.dart reported 1 hint:

line 165 col 11: Close instances of dart.core.Sink.

Fix lib/data/services/rest_api/helpers/user.dart. (-0.50 points)

Analysis of lib/data/services/rest_api/helpers/user.dart reported 1 hint:

line 5 col 30: The field doesn't override an inherited getter or setter.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
bloc ^3.0.0 3.0.0 4.0.0-dev.1
firebase ^7.2.1 7.3.0
firebase_auth ^0.15.5+2 0.15.5+3
flutter 0.0.0
flutter_bloc ^3.2.0 3.2.0 4.0.0-dev.1
http ^0.12.0+4 0.12.0+4
meta ^1.1.8 1.1.8
path_provider ^1.6.5 1.6.5
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
firebase_auth_platform_interface 1.1.7
firebase_auth_web 0.1.2
firebase_core 0.4.4+3
firebase_core_platform_interface 1.0.4
firebase_core_web 0.1.1+2
flutter_web_plugins 0.0.0
http_parser 3.1.4
js 0.6.1+1
matcher 0.12.6
nested 0.0.4
path 1.6.4
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
pedantic 1.9.0
platform 2.2.1
plugin_platform_interface 1.0.2
provider 4.0.4 4.1.0-dev+2
quiver 2.1.3
rxdart 0.23.1 0.24.0-dev.1
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test