Authentication
ShipFlutter uses Firebae Authentication as a backend, offering a set of authentication methods that you can use to authenticate your users, in addition to a responsive login page that handles social signin, email-password, anonymous auth, as well as verification and recover flow.
Before starting, make sure you have completed the Firebase setup, including the Firebase Authentication steps.
Features
The authentication module provides the following features:
- Multiple sign-in methods (Email/Password, Anonymous, Social)
- Secure credential management
- Real-time authentication state
- Email verification
- Password recovery
- Account deletion
- Social authentication (Google, Apple, Facebook)
- Custom claims support
- Handles reauthorization dialog
Overview
The authentication module is structured in the following way:
Directoryaccount/access
- auth_view.dart // Responsive login page
- auth_dialog.dart // Utility dialogs (e.g recover password)
- auth_route.dart // Navigation logic
- auth_controller.dart // Business logic and state
- auth_service.dart // Connector to the Firebase Auth Backend
- credentials.dart // Model class with user auth data
- credentials_controller.dart // Observes changes in the credentials
Directoryfirebase/
Directoryauth/
- auth_service.dart // Connector to the Firebase Auth Backend
AuthService
The AuthService
class (in core/firebase/auth
) is the main interface for authentication operations. It provides methods for:
Credentials Model
The Credentials
class (in core/account/credentials
) represents the user’s authentication state:
Error Handling
The UI automatically handles common authentication errors:
AuthView
ShipFlutter provides a responsive and customizable authentication UI that adapts to different screen sizes and orientations. The UI is implemented in the core/account/access
module.
Features
-
Responsive Design
- Portrait mode for mobile devices
- Landscape mode for tablets and desktops
- Adapts to different screen sizes
-
Multiple Authentication Methods
- Email/Password form with validation
- Social login buttons (Google, Apple, Facebook)
- Anonymous login option with “Skip for now” option
-
User-Friendly Experience
- Clear error messages
- Loading indicators
- Smooth animations
- Form validation
Customization
The UI is built with Material Design 3 and automatically adapts to your app’s theme. You can customize:
-
Colors and Typography
-
Text and Labels
-
Social Login Providers
How to use it
You can either use the UI components or the controller directly:
Security Best Practices
-
Always Handle Authentication Errors
- Use the
AuthError
type to handle specific error cases - Provide appropriate user feedback for each error type
- Use the
-
Verify Email When Required
- Check
credentials.type
to determine verification status - Use
sendVerifyEmail()
for unverified accounts
- Check
-
Secure Token Management
- Never store tokens in plain text
- Use the built-in token management system
-
Regular Reauthorization
- Use
reauthenticate()
for sensitive operations - Handle
requires-recent-login
errors appropriately
- Use
Error Handling
The authentication module uses the AuthError
class which provides specific error types:
Handle errors appropriately in your UI: