๐Ÿ“ฆ simple_firebase_auth

A lightweight and opinionated wrapper around firebase_auth and firebase_core to simplify Firebase authentication logic in Flutter.

โœ… Firebase initialization
โœ… Sign in / Sign up with Email & Password
โœ… Password reset
โœ… Sign out
โœ… Auth state changes stream
โœ… Minimal setup, beginner-friendly API


โœจ Features

  • ๐Ÿš€ One-liner Firebase init
  • ๐Ÿง  Clean custom user model (AuthUser)
  • ๐Ÿ“ก Stream-based auth state monitoring
  • ๐Ÿ” Simple sign in / sign up / reset / logout methods
  • ๐Ÿ” Zero FirebaseAuth.instance boilerplate in your app code

๐Ÿš€ Getting Started

1. Add dependencies

dependencies:
  simple_firebase_auth: ^0.0.1

This package internally uses:

  • firebase_auth
  • firebase_core

2. Initialize Firebase (main.dart)

void main() async {
  await SimpleFirebaseAuth.instance.initialize(); // Required
  runApp(const MyApp());
}

๐Ÿง‘โ€๐Ÿ’ป Usage Example

๐Ÿ” Sign In / Sign Up / Reset

final auth = SimpleFirebaseAuth.instance;

final user = await auth.signIn('test@email.com', 'password123');
// or:
final user = await auth.signUp('new@email.com', 'secretPassword');

await auth.sendPasswordReset('forgot@email.com');
await auth.signOut();

๐Ÿ‘ค Get Current User

final user = await SimpleFirebaseAuth.instance.currentUser();
if (user != null) print(user.uid);

๐Ÿ“ก Listen to Auth State

StreamBuilder<AuthUser?>(
  stream: SimpleFirebaseAuth.instance.authState(),
  builder: (context, snapshot) {
    final user = snapshot.data;
    if (user == null) return const SignInPage();
    return HomePage(user: user);
  },
);

๐Ÿ“„ AuthUser Model

This package exposes a simplified user model:

class AuthUser {
  final String uid;
  final String? email;
  final bool isAnonymous;
}

๐Ÿงช Example

Run the example app:

cd example
flutter run

Youโ€™ll find:

  • TextFields for email & password
  • Buttons for sign in, sign up, reset password
  • Auth state and user UID displayed

๐Ÿ”’ Firebase Setup

This package assumes youโ€™ve already:

  1. Added google-services.json (Android) and/or GoogleService-Info.plist (iOS)
  2. Enabled Email/Password sign-in method in Firebase Console
  3. Installed firebase_auth and firebase_core

Web/desktop users should pass FirebaseOptions to initialize().


๐Ÿ“ฆ Coming Soon

  • Google / Apple / Phone Sign-In
  • Firebase Emulator support
  • Provider/Riverpod/BLoC adapters

๐Ÿ™Œ License

MIT ยฉ Chauhan Pruthviraj


๐Ÿ›  How to Run the Example App

๐Ÿ“ Project Structure

simple_firebase_auth/
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ simple_firebase_auth.dart
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ””โ”€โ”€ simple_firebase_auth_impl.dart
โ”œโ”€โ”€ example/
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ””โ”€โ”€ main.dart
โ”œโ”€โ”€ pubspec.yaml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ test/

๐Ÿ”ฅ Firebase Setup

โœ… Android

  1. Go to Firebase Console and create a project
  2. Add an Android app
  3. Download google-services.json and place it in:
    example/android/app/google-services.json
    
  4. In example/android/build.gradle (project-level):
    classpath 'com.google.gms:google-services:4.3.15'
    
  5. In example/android/app/build.gradle:
    apply plugin: 'com.google.gms.google-services'
    

โœ… iOS

  1. Add an iOS app in Firebase Console
  2. Download GoogleService-Info.plist
  3. Place it in:
    example/ios/Runner/GoogleService-Info.plist
    
  4. Ensure minimum iOS version is set in example/ios/Podfile:
    platform :ios, '11.0'
    

๐Ÿงฉ Add Dependencies in example/pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  firebase_core: ^3.15.0
  firebase_auth: ^5.6.1

  simple_firebase_auth:
    path: ../

Then run:

flutter pub get

โ–ถ๏ธ Run the App

cd example
flutter run

๐Ÿ”“ Enable Email/Password Authentication

  1. Go to Firebase Console
  2. Navigate to Authentication > Sign-in method
  3. Enable Email/Password

Now you're ready to test sign-in, sign-up, reset password, and sign-out flows in the running app!