Flutter Firebase Auth SDK
A reusable Authentication SDK powered by Firebase that supports both a pre-built UI and a no-UI mode for custom implementation.
Features
- Dual Mode UI:
- Default Mode: Plug-and-play
AuthScreenwidget. - Headless Mode: Exposed
AuthServiceand streams for building custom UIs.
- Default Mode: Plug-and-play
- Unified Error Handling: Maps Firebase errors to custom exceptions (
UserNotFoundException,InvalidCredentialsException, etc.). - Configurable: Enable/disable providers via
AuthConfig. - State Management: Built-in streams for
Authenticated,Unauthenticated,TokenExpired.
Installation
- Add the dependency to your
pubspec.yaml:
dependencies:
flutter_firebase_auth_sdk:
path: path/to/flutter_firebase_auth_sdk
- (Optional) For full Firebase support, ensure you have configured your Flutter app with Firebase:
Usage
1. Default Mode (Pre-built UI)
import 'package:flutter_firebase_auth_sdk/arc_firebase_auth_sdk.dart';
// ...
AuthScreen(
config: AuthConfig(
enableEmailPassword: true,
enableGoogle: true,
enableApple: true,
),
authService: FirebaseAuthService(), // Or MockAuthService() for testing
onAuthSuccess: () {
print("User authenticated!");
},
);
2. Headless Mode (Custom UI)
final authService = FirebaseAuthService();
// Sign In
try {
await authService.signInWithEmailAndPassword(
email: 'test@example.com',
password: 'password'
);
} on AuthException catch (e) {
print(e.message);
}
// Listen to state
StreamBuilder<AuthState>(
stream: authService.authStateChanges,
builder: (context, snapshot) {
if (snapshot.data?.status == AuthStatus.authenticated) {
return HomePage();
}
return LoginPage();
},
);
Error Handling
The SDK maps Firebase errors to specific exceptions:
InvalidCredentialsException: Wrong email/password.UserNotFoundException: User does not exist.EmailAlreadyInUseException: Email already registered.WeakPasswordException: Password is too weak.NetworkException: Network connectivity issues.
##Screenshot