hack_auth π
Plug-and-play Firebase authentication for Flutter hackathons.
Install β configure β ship. Done in under 5 minutes.
β¨ Features
| Feature | Included |
|---|---|
| Email / Password Login | β |
| Registration (with display name) | β |
| Forgot Password (email link) | β |
| Logout | β |
| AuthGate (auto-routing) | β |
| Friendly Firebase error messages | β |
| Dark-mode UI out of the box | β |
| Fully customisable theme | β |
π Quick Start
1. Add to pubspec.yaml
dependencies:
hack_auth: ^0.1.0
2. Enable Firebase
This package requires a Firebase project with Email/Password authentication enabled.
The easiest way to configure Firebase is with the FlutterFire CLI:
dart pub global activate flutterfire_cli
flutterfire configure
Or pass FirebaseOptions manually (see Step 3).
3. Initialize
import 'package:hack_auth/hack_auth.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await HackAuth.initialize(
firebaseOptions: FirebaseOptions(
apiKey: 'YOUR_API_KEY',
appId: 'YOUR_APP_ID',
messagingSenderId: 'YOUR_MESSAGING_SENDER_ID',
projectId: 'YOUR_PROJECT_ID',
),
theme: HackAuthTheme(primaryColor: Colors.indigo), // optional
);
runApp(MyApp());
}
4. Add AuthGate
MaterialApp(
home: AuthGate(
authenticated: HomePage(),
unauthenticated: LoginPage(),
),
);
That's it. π Your app now has a working login, registration, and forgot-password flow.
π± Screens
LoginPage
LoginPage(
title: 'Welcome Back', // optional
loginButtonText: 'Sign In', // optional
theme: HackAuthTheme(...), // optional
onLoginSuccess: () {
// called after successful login
// if using AuthGate, you don't need this
},
)
RegisterPage
RegisterPage(
title: 'Create Account',
registerButtonText: 'Sign Up',
onRegisterSuccess: () { ... },
)
ForgotPasswordPage
ForgotPasswordPage(
title: 'Reset Password',
onEmailSent: () { ... },
)
π¨ Theming
HackAuthTheme(
primaryColor: Color(0xFF6C63FF),
backgroundColor: Color(0xFF0F0F1A),
surfaceColor: Color(0xFF1C1C2E),
textColor: Color(0xFFEFEFEF),
hintColor: Color(0xFF8A8A9A),
errorColor: Color(0xFFFF5C5C),
borderRadius: 14,
logo: AssetImage('assets/logo.png'), // shown on all screens
logoHeight: 80,
)
π Direct API Usage
// Login
await HackAuth.login(email: email, password: password);
// Register
await HackAuth.register(email: email, password: password);
// Logout
await HackAuth.logout();
// Reset password
await HackAuth.resetPassword(email: email);
// Current user
final user = HackAuth.currentUser;
print(user?.email);
// Auth state stream
HackAuth.authStateChanges.listen((user) { ... });
All methods throw HackAuthException on failure:
try {
await HackAuth.login(email: email, password: password);
} on HackAuthException catch (e) {
print(e.message); // "No account found with this email."
}
ποΈ Package Architecture
hack_auth/
βββ lib/
β βββ hack_auth.dart β Public API barrel
β βββ src/
β βββ hack_auth_main.dart β HackAuth static facade
β βββ config/
β β βββ hack_auth_theme.dart
β βββ models/
β β βββ auth_result.dart
β β βββ auth_exception.dart
β βββ services/
β β βββ auth_service.dart
β βββ screens/
β β βββ login_page.dart
β β βββ register_page.dart
β β βββ forgot_password_page.dart
β βββ widgets/
β βββ auth_button.dart
β βββ auth_text_field.dart
β βββ auth_gate.dart
βββ example/
βββ lib/main.dart
π License
MIT Β© 2024 β (https://github.com/Atharva660)
Libraries
- hack_auth
- hack_auth β Plug-and-play Firebase authentication for Flutter hackathons.