πŸ“¦ 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!