A Flutter application demonstrating user email verification and validation.
- Email Validation: Validates email format before sending verification codes.
- Verification Code Sending: Sends authentication codes to user emails.
- Code Verification: Validates the 6-digit code entered by users.
- Verification Cancellation: Allows users to cancel the verification process.
- Error Handling: Provides clear feedback for various error scenarios.
- Loading States: Manages loading states during asynchronous operations.
This project follows a layered MVVM-like architecture, primarily within the lib
directory, promoting separation of concerns and maintainability. It utilizes the Riverpod package for state management and dependency injection, and GoRouter for navigation.
Firebase (Authentication and Cloud Functions) is used as the backend for authentication logic and user management.
The project uses Firebase Cloud Functions to handle authentication logic. The following functions are implemented:
-
hello_world
- A simple test function that returns "Hello world from on_call!"
- Used to verify the Cloud Functions setup is working correctly
-
send_auth_code_on_call
- Sends an authentication code to the provided email address
- Requires
email
andservice
parameters - Supports two email sending services: "sengrid" for SendGrid and "dummy" for testing
- Returns a verification ID and status information
-
verify_auth_code_on_call
- Verifies the authentication code entered by the user
- Requires
verification_id
andcode
parameters - Returns success status and user ID when verification succeeds
- Returns appropriate error messages when verification fails
-
delete_auth_code_on_call
- Deletes an authentication code from the system
- Requires
verification_id
parameter - Used when canceling the verification process
- Returns confirmation message upon successful deletion
These functions work with the AuthService
class to manage the authentication flow, including code generation, storage, verification, and cleanup.
Follow these steps to get the application running:
-
Prerequisites:
- Ensure you have the Flutter SDK installed.
- Ensure you have a Firebase project set up.
- Enable Firebase Authentication (e.g., Email/Password).
- If using Cloud Functions, deploy the necessary functions to your Firebase project.
- Configure your Flutter app with Firebase using
flutterfire configure
.
-
Clone the repository
git clone https://github.com/cristianpalomino/authentication_challenge cd authentication_challenge
-
Install dependencies:
flutter pub get
-
Run the app (e.g., on Chrome): Make sure Chrome is installed or an emulator/device is running. Then, run:
flutter run -d chrome
This will build and launch the application.
-
Running Unit Tests: To run the unit tests included in the project, use:
flutter test
Screenshots:
Video Recording: