hack_auth πŸ”

pub.flutter-io.cn License: MIT

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.