sam0829 / firebase_auth_ui

Flutter plugin for Firebase Auth UI. Supports popular auth providers by using native SDK for Android and iOS.
https://pub.dev/packages/firebase_auth_ui
BSD 3-Clause "New" or "Revised" License
48 stars 20 forks source link
firebase-auth firebase-authui flutter flutter-examples flutter-package flutter-plugin

firebase_auth_ui

Flutter plugin of Firebase UI which allows to add login/sign-up quickly.

NOTE: This plugin is under development. Please provide Feedback and Pull Requests in order to have your feature(s) integrated.

Screenshot

Usage

Import

import 'package:firebase_auth_ui/firebase_auth_ui.dart';
import 'package:firebase_auth_ui/providers.dart';

Use of the plugin

Present the auth screen
FirebaseAuthUi.instance()
        .launchAuth(
          [
            AuthProvider.email(), // Login/Sign up with Email and password
            AuthProvider.google(), // Login with Google
            AuthProvider.facebook(), // Login with Facebook
        AuthProvider.twitter(), // Login with Twitter
        AuthProvider.phone(), // Login with Phone number
          ],
          tosUrl: "https://my-terms-url", // Optional
          privacyPolicyUrl: "https://my-privacy-policy", // Optional,
        )
        .then((firebaseUser) =>
            print("Logged in user is ${firebaseUser.displayName}"))
        .catchError((error) => print("Error $error"));
Logout
void logout() async {
    final result = await FirebaseAuthUi.instance().logout();
    // ...
}
Delete
void delete() async {
    final result = await FirebaseAuthUi.instance().delete();
    // ...
}

Plugin returns FirebaseUser with following details:

Field Description
uid UID of authenticated user
displayName Display name of user
email Email of user
phoneNumber Phone number of user
photoUri URI of user's photo
providerId Indicates through which provider user was authenticated.
isNewUser Indicates if user is new
metaData Object of MetaData

MetaData

Field Description
creationTimestamp Timestamp of user's creation
lastSignInTimestamp Timestamp of user's last sign in

Notes:

If you want to have full FirebaseUser object then please add firebase_auth dependency. You can then use FirebaseAuth.instance.currentUser().

Configuration

Create a project on Firebase console and add Android and iOS platform in Settings > Your apps

Android

Open project's build.gradle ([flutter_project]/android/build.gradle) and add following in dependencies{ ... }:

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

Open app module's build.gradle ([flutter_project]/android/app/build.gradle) and add following at the end of file, i.e as a last line:

apply plugin: 'com.google.gms.google-services'

Copy the downloaded google-services.json in [flutter_project]/android/app directory.

iOS

Copy the downloaded GoogleService-Info.plist in [[flutter_project]/ios/Runner directory.

Additional setup for Google, Facebook, Twitter and Phone sign-in

Google

Android

No additional setup required.

iOS

Phone number

Android

No additional setup required.

iOS

If you have already configured Google sign-in for iOS following above steps, then you don't need to do anything else. If not, please follow the exact same step.

Customization

Add logo

Rename your icon to auth_ui_logo.png then follow below steps:

Android

Android specific

Misc