TesteraAuth
A Flutter plugin that provides a simple authentication layer for your app using a code-based validation system.
Features
- Code-based authentication
- Persistent authentication state
- Modern, responsive UI design
- App usage tracking and analytics
- Package name and installer store detection
- Automatic usage logging to cloud functions
- Built-in app store links
Installation
Add this to your package's pubspec.yaml
file:
dependencies:
testera_auth: ^1.2.0
Usage
- Wrap your app with
GetMaterialApp
and useTesteraAuth
as the home widget:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:testera_auth/testera_auth.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'My App',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const TesteraAuth(
child: HomeScreen(),
),
);
}
}
- Create your main screen that will be shown after successful authentication:
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My App'),
),
body: const Center(
child: Text('Welcome to the authenticated app!'),
),
);
}
}
Configuration
The TesteraAuth
widget accepts the following parameters:
child
(required): The widget to display when authenticated
Usage Tracking
The plugin automatically tracks and logs app usage to the configured cloud function. The following events are tracked:
- App start
- App background
- App close
Each usage log includes:
- Validation code
- Session duration
- Package name
- Installer store information
- App name
Error Handling
The plugin includes robust error handling for:
- Network connectivity issues
- Invalid codes
- Package info retrieval
- Lifecycle state changes
- Usage logging failures
All errors are gracefully handled to prevent app crashes and maintain a smooth user experience.
Plugin must be applied anywhere after the GetMeterialApp or MaterialApp, not before. If you are using routes, wrap your initial screen with TesteraAuth.
Since Splash screens are usually transitive, it is not advisable to apply the plugin on transitive screens.
Security
- Authentication state is persisted securely using SharedPreferences
- Validation codes are stored securely and cleared on expiration
- All network requests are made over HTTPS
- Error messages are sanitized to prevent information leakage
Authentication
The plugin uses a simple code-based authentication system:
- Authentication state persists until code expiration
- Expiration duration is configurable (default: 7 days)
State Management
The plugin uses default flutter state management.
Example
Check out the testera_auth_example directory for a complete working example.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.