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

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

canNavigateBack → bool
Whether it is possible to navigate back to the previous screen.
no setter
client → ServerpodClientShared
The Serverpod client instance.
finalinherited
completePasswordResetScreen → EmailFlowScreen
The screen for setting the new password of a password reset.
no setteroverride
currentScreen → EmailFlowScreen
The current screen in the authentication flow.
no setterinherited
emailController → TextEditingController
Text controller for email input.
latefinalinherited
emailEndpoint → EndpointEmailIdpBase
The email authentication endpoint of the client.
no setterinherited
emailValidation → void Function(String email)
The validation function to use for email validation.
finalinherited
error → Object?
The current error, if any.
no setterinherited
errorMessage → String?
The current error message, if any.
no setterinherited
finishRequestToken ↔ String?
The token to finish the current request, set after its verification code is verified.
getter/setter pairinherited
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 setterinherited
isLoading → bool
Whether the controller is currently processing a request.
no setterinherited
legalNoticeAcceptedNotifier → ValueNotifier<bool>
Notifier for terms and conditions / privacy policy acceptance checkbox.
latefinalinherited
onAuthenticated → VoidCallback?
Callback when authentication is successful.
finalinherited
onError → dynamic Function(Object error)?
Callback when an error occurs during authentication.
finalinherited
passwordController → TextEditingController
Text controller for password input.
latefinalinherited
passwordRequirements → List<PasswordRequirement>
Optional list of password requirements to display to the user.
finalinherited
requestId ↔ UuidValue?
The request ID of the current flow, if any.
getter/setter pairinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
startScreen → EmailFlowScreen
The screen to display when starting the flow.
finalinherited
state → EmailAuthState
The current state of the authentication flow.
no setterinherited
verificationCodeController → TextEditingController
Text controller for verification code input.
latefinalinherited
verifyPasswordResetScreen → EmailFlowScreen
The screen showing the verification of the password reset code.
no setteroverride

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.
inherited
finishPasswordReset() → Future<void>
Completes the password reset process with a new password.
inherited
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.
inherited
Navigates back to the previous screen in the authentication flow.
Navigates to a specific screen in the authentication flow.
override
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.
override
resetState({bool notify = true}) → void
Clears the text controllers and previously set request ID, if not on a verification code screen. Pass notify as false if calling before navigateTo to avoid notifying listeners twice.
inherited
runGuarded(Future<EmailFlowScreen?> action()) → Future<void>
Executes the given action and navigates to the screen it returns, or transitions to the authenticated state and calls onAuthenticated if it returns null.
inherited
setState(EmailAuthState newState, {bool notify = true}) → void
Sets the current state of the authentication flow and notifies listeners.
inherited
showScreen(EmailFlowScreen screen) → void
Shows screen and resets the state to idle.
inherited
startPasswordReset() → Future<void>
Starts the password reset process.
inherited
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.
inherited
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 = true}) → void
Default email validation function.
override