π¦ 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:
- Added
google-services.json
(Android) and/orGoogleService-Info.plist
(iOS) - Enabled Email/Password sign-in method in Firebase Console
- Installed
firebase_auth
andfirebase_core
Web/desktop users should pass
FirebaseOptions
toinitialize()
.
π¦ 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
- Go to Firebase Console and create a project
- Add an Android app
- Download
google-services.json
and place it in:example/android/app/google-services.json
- In
example/android/build.gradle
(project-level):classpath 'com.google.gms:google-services:4.3.15'
- In
example/android/app/build.gradle
:apply plugin: 'com.google.gms.google-services'
β iOS
- Add an iOS app in Firebase Console
- Download
GoogleService-Info.plist
- Place it in:
example/ios/Runner/GoogleService-Info.plist
- 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
- Go to Firebase Console
- Navigate to Authentication > Sign-in method
- Enable Email/Password
Now you're ready to test sign-in, sign-up, reset password, and sign-out flows in the running app!