Giter Club home page Giter Club logo

fireauth's Introduction

Fireauth

FireAuth is a Flutter Package that aims to simplify Flutter Firebase Authentication and streamline app development. It provides a intuitive way to access Parts of the Firebase Authentication Suite and reduces the amount of time you have to spend on it. Works for both Flutter Native and Flutter Web!

Install

Add this line to your pubspec.yaml:

dependencies:
  fireauth: ^0.9.0

Then run this command:

$ flutter packages get

Then add this import:

import 'package:fireauth/fireauth.dart';

Project Firebase Setup

Setting up Firebase correctly to work with all the Authentication Methods provided by FireAuth can sometimes be difficult and tedious! Hence, I have come up with a python script that will do most of the hardwork for you! It also contains well documented instructions so that the entire process is very smooth. It's better than the official documentation!

๐Ÿ”ด If you do not use FireSetup there could be some issues due to incorrect manual setup.

Platform Support

  • Android (Full Support)
  • Web (Full Support)
  • iOS (Full Support)
  • macOS ( Dependencies Unsupported )
  • Windows ( Dependencies Unsupported )
  • Linux ( Dependencies Unsupported )

Currently Supported Authentication Methods:

  • Anonymous
  • Email & Password Register & SignIn
  • Phone
  • Google
  • Twitter
  • Github
  • Microsoft
  • Facebook
  • Yahoo
  • Apple (Untested)
  • Passwordless (Implementation Pending)

โš ๏ธ Most of these Authentication Methods need extra setup! Everything is documented very well in the FireSetup README


Usage

โ˜‘๏ธ fireauth exports and exposes the firebase_core, firebase_auth and provider packages by default! Hence, you need not import them separately! This ensures you do not clutter your project with multiple imports! You can find the dependency versions here

Step 1: Initializing Firebase (main.dart)

void main() async {
  //This initializes Firebase Accordingly (Important)
  await initializeFirebase();  //This method is from the fireauth package
  runApp(YourApp());
}

Step 2: Wrap your Material App with FireAuth

//Allows the Authentication Methods to be accessible from anywhere in the widget tree
return FireAuth(
   child: MaterialApp(
     home: MyAppHome(),
   ),
);

Step 3: Use the AuthManager

//This basically acts like a Gateway, If youre logged in, it shows the destinationFragment
//else it shows the loginFragment (It Remembers the Authentication State too!)

return AuthManager(
  loginFragment: LoginPage(),
  destinationFragment: HomePage(),
);

Using the AuthController

The AuthController is a Dart class that contains several static methods that exposes useful functions!

For more information on these methods, take a look at them using the IDE, they are very well documented, but this is all you need for it to work in the default way

Sign In With Google

๐ŸŸก GoogleSignIn Needs Additional Setup

AuthController.signInWithGoogle(
  context,
  onError: (String e) {},
  onSignInSuccessful: (User u) {},
);

Anonymous SignIn

AuthController.signInAnonymously(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

Phone SignIn

๐ŸŸก PhoneSignIn Needs Additional Setup

AuthController.signInWithPhoneNumber(
    context,
    phoneNumber: phoneNumberController.value.text,
    onError: (e) {},
    onInvalidVerificationCode: () {},
    onSignInSuccessful: (User u) {},
  );
};

Register & Login With Email & Password

AuthController.registerWithEmailAndPassword(
  context,
  email: "[email protected]",
  password: "abc123",
  onError: (String e) {},
  onRegisterSuccessful: (User u) {},
);

SignIn With Email & Password

AuthController.signInWithEmailAndPassword(
  context,
  email: "[email protected]",
  password: "abc123",
  onError: (String e) {},
  onIncorrectCredentials: () {},
  onSignInSuccessful: (User u) {},
);

SignIn With Facebook

๐ŸŸก FacebookSignIn Needs Additional Setup

AuthController.signInWithFacebook(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

SignIn Using OAuth2

๐ŸŸก OAuthSignIn Needs Additional Setup

//Twitter OAuth SignIn
AuthController.signInWithTwiter(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

//Github OAuth SignIn
AuthController.signInWithGithub(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

//Microsoft OAuth SignIn
AuthController.signInWithMicrosoft(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

//Yahoo OAuth SignIn
AuthController.signInWithYahoo(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

//Apple OAuth SignIn (Native on iOS)
AuthController.signInWithApple(
  context,
  onSignInSuccessful: (User u) {},
  onError: (String e) {},
);

Logout

AuthController.logout(context);

Get Current User

AuthController.getCurrentUser(
  context,
  //Optional Arguement, if not provided, It just returns a Firebase User
  customMapping: (user) => {
    'name': user.displayName,
    'email': user.email,
  },
);

Social SignIn Buttons

If you just want a ready to use button that enables a particular Social SignIn, This is these are the Widgets that you're looking for!

import 'package:fireauth/fireauth.dart';

//SocialButtons
TwitterSocialButton(),
GithubSocialButton(),
MicrosoftSocialButton(),
GoogleSocialButton(),
FacebookSocialButton(),
//This Button Uses the new Facebook Design Language
NewFacebookSocialButton(),
YahooSocialButton(),
AnonymousSocialButton(),
AppleSocialButton(),

//MiniSocialButtons
MiniTwitterSocialButton(),
MiniGithubSocialButton(),
MiniMicrosoftSocialButton(),
MiniGoogleSocialButton(),
MiniFacebookSocialButton(),
//This Button Uses the new Facebook Design Language
MiniNewFacebookSocialButton(),
MiniAnonymousSocialButton(),
MiniYahooSocialButton(),
AppleSocialButton(),

/* Each of these buttons accept a SocialButtonConfiguration! Ex:
GoogleSocialButton(
  config: SocialButtonConfiguration(
    foregroundColor: Colors.black,
    backgroundColor: Colors.white,
    onSignInSuccessful: (user) {
      print("GoogleSignIn Successful!!! UID: ${user.uid}");
    },
    onError: (e) {
      showDialog(
        context: context,
        builder: (context) => AlertDialog(
          title: Text("GoogleOAuth Error Occured"),
          content: Text(e),
        ),
      );
    },
  ),
),
More info provided in the Docstring of the SocialButtonConfiguration class
*/

Future Plans

  • Move FireAuth to sound null safety
  • Declare Production Ready Status

fireauth's People

Contributors

neuron-code avatar synapsecode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.