AuthRepository class abstract
Abstract repository for authentication operations
This repository defines the contract for authentication adapters. Implementations can support various authentication providers including:
- Email/Password (Firebase, Auth0, custom backend)
- OAuth providers (Google, Facebook, Apple, GitHub)
- Phone authentication
- Anonymous authentication
- Custom token authentication
Implementing an Auth Adapter
To create an authentication adapter, extend this class and implement
the required methods. Not all methods need to be implemented - you can
throw UnimplementedError for unsupported features.
Example: Firebase Auth Adapter
class FirebaseAuthRepository extends AuthRepository {
final FirebaseAuth _auth = FirebaseAuth.instance;
@override
Future<AuthResult> signIn(AuthCredentials credentials) async {
if (credentials is EmailPasswordCredentials) {
try {
final userCredential = await _auth.signInWithEmailAndPassword(
email: credentials.email,
password: credentials.password,
);
return AuthResult.success(
user: _mapFirebaseUser(userCredential.user!),
token: await userCredential.user!.getIdToken(),
);
} catch (e) {
return AuthResult.failure(errorMessage: e.toString());
}
}
throw UnimplementedError('Credential type not supported');
}
}
- Inheritance
-
- Object
- CoreRepository
- AuthRepository
Constructors
Properties
-
authStateChanges
→ Stream<
User?> -
Stream of authentication state changes
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
changePassword(
{required String currentPassword, required String newPassword}) → Future< PasswordResetResult> - Change the password for the currently authenticated user
-
confirmPasswordReset(
{required String code, required String newPassword}) → Future< PasswordResetResult> - Confirm password reset with the provided code and new password
-
deleteAccount(
) → Future< void> - Delete the current user's account
-
enrollMFA(
{required String phoneNumber}) → Future< void> - Enroll in multi-factor authentication
-
getCurrentUser(
) → Future< User?> - Get the currently authenticated user
-
getIdToken(
{bool forceRefresh = false}) → Future< String?> - Get a fresh authentication token for the current user
-
initialize(
) → void -
Initialize the repository
inherited
-
linkCredential(
AuthCredentials credentials) → Future< AuthResult> - Link an additional authentication method to the current user
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refreshToken(
String refreshToken) → Future< AuthResult> - Refresh the authentication token using a refresh token
-
sendEmailVerification(
) → Future< void> - Send email verification to the current user
-
sendPasswordResetEmail(
String email) → Future< PasswordResetResult> - Send a password reset email to the specified email address
-
sendPhoneVerificationCode(
String phoneNumber) → Future< void> - Send phone verification code to the specified phone number
-
signIn(
AuthCredentials credentials) → Future< AuthResult> - Sign in a user with the provided credentials
-
signOut(
) → Future< void> - Sign out the currently authenticated user
-
signUp(
AuthCredentials credentials, {String? displayName, String? photoUrl, Map< String, dynamic> ? metadata}) → Future<AuthResult> - Sign up a new user with the provided credentials
-
toString(
) → String -
A string representation of this object.
inherited
-
unenrollMFA(
) → Future< void> - Unenroll from multi-factor authentication
-
unlinkProvider(
String providerId) → Future< User> - Unlink an authentication method from the current user
-
updateEmail(
String newEmail) → Future< User> - Update the current user's email address
-
updateProfile(
{String? displayName, String? photoUrl, Map< String, dynamic> ? metadata}) → Future<User> - Update the current user's profile information
-
verifyEmail(
String code) → Future< EmailVerificationResult> - Verify email with the provided verification code
-
verifyPhoneNumber(
{required String phoneNumber, required String verificationCode}) → Future< EmailVerificationResult> - Verify phone number with the provided verification code
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited