EmailAuthController class
Controller for managing email-based authentication flows.
This controller handles all the business logic for email authentication, including login, registration, and email verification. It can be used with any UI implementation.
Example usage:
final controller = EmailAuthController(
client: client,
onAuthenticated: () {
// Do something when the user is authenticated.
//
// NOTE: You should not navigate to the home screen here, otherwise
// the user will have to sign in again every time they open the app.
},
);
// Login
await controller.login();
// Start registration
await controller.startRegistration();
// Finish registration
await controller.finishRegistration();
// Listen to state changes
controller.addListener(() {
// UI will rebuild automatically
// Can use `controller.state` to access the current state.
});
- Inheritance
-
- Object
- ChangeNotifier
- EmailAuthController
Constructors
-
EmailAuthController({required ServerpodClientShared client, EmailFlowScreen startScreen = EmailFlowScreen.login, VoidCallback? onAuthenticated, dynamic onError(Object error)?, void emailValidation(String email)?, List<
PasswordRequirement> ? passwordRequirements}) - Creates an email authentication controller.
Properties
-
Whether it is possible to navigate back to the previous screen.
no setter
- client → ServerpodClientShared
-
The Serverpod client instance.
final
- currentScreen → EmailFlowScreen
-
The current screen in the authentication flow.
no setter
- emailController → TextEditingController
-
Text controller for email input.
latefinal
- emailValidation → void Function(String email)
-
The validation function to use for email validation.
final
- error → Object?
-
The current error, if any.
no setter
- errorMessage → String?
-
The current error message, if any.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isAuthenticated → bool
-
Whether the user is authenticated.
no setter
- isLoading → bool
-
Whether the controller is currently processing a request.
no setter
-
legalNoticeAcceptedNotifier
→ ValueNotifier<
bool> -
Notifier for terms and conditions / privacy policy acceptance checkbox.
latefinal
- onAuthenticated → VoidCallback?
-
Callback when authentication is successful.
final
- onError → dynamic Function(Object error)?
-
Callback when an error occurs during authentication.
final
- passwordController → TextEditingController
-
Text controller for password input.
latefinal
-
passwordRequirements
→ List<
PasswordRequirement> -
Optional list of password requirements to display to the user.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- startScreen → EmailFlowScreen
-
The screen to display when starting the flow.
final
- state → EmailAuthState
-
The current state of the authentication flow.
no setter
- verificationCodeController → TextEditingController
-
Text controller for verification code input.
latefinal
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
finishPasswordReset(
) → Future< void> - Completes the password reset process with a new password.
-
finishRegistration(
) → Future< void> - Completes the registration process with the verification code.
-
login(
) → Future< void> - Logs in a user with email and password from the text controllers.
- Navigates back to the previous screen in the authentication flow.
- Navigates to a specific screen in the authentication flow.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
resendVerificationCode(
) → Future< void> - Resends the verification code based on the current screen.
-
resetState(
{bool notify = true}) → void -
Clears the text controllers and previously set request ID, if not on
a verification code screen. Pass
notifyasfalseif calling before navigateTo to avoid notifying listeners twice. -
startPasswordReset(
) → Future< void> - Starts the password reset process.
-
startRegistration(
) → Future< void> - Starts the registration process for a new user with email only.
-
toString(
) → String -
A string representation of this object.
inherited
-
verifyPasswordResetCode(
) → Future< void> - Verifies the password reset verification code.
-
verifyRegistrationCode(
) → Future< void> - Submits the registration process and sends verification email.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
validateEmail(
String email, {bool allowTopLevelDomains = false, bool allowEmailAliases = false}) → void - Default email validation function.