Register & Login
Create new user accounts and authenticate existing users with email and password.
Register
Creates a new user account. Returns a SignUpResult carrying the created user and whether the project requires verification before sign-in. The password is hashed server-side before storage — never stored in plaintext.
lib/auth.dart
Dart
final result = await Koolbase.auth.signUp(
email: '[email protected]',
password: 'securepassword',
);
if (result.verificationRequired) {
// Account created, but NOT signed in — this project requires a
// verified contact channel. Send them to a "check your email" screen.
showVerifyScreen(result.user.email);
} else {
// Signed in — the session is stored and the app can proceed.
goHome(result.user);
}
print(result.user.id); // UUID
print(result.user.verified); // false — email not yet verifiedBreaking change in 11.0.0
On Flutter,
signUp previously returned the user directly. It now returns SignUpResult, because a project can require a verified contact channel before any session is issued — and the old return type could not express "account created, not signed in". If your project does not require verified contact (the default), verificationRequired is always false and result.user behaves exactly as the old return value. In React Native and on the web, register returns the same result, with status 'authenticated' or 'verification_required'.Email verification
Newly registered users have
verified: false. Koolbase emails them a verification link when they register. If it expires or gets lost, send a fresh one with Koolbase.auth.resendVerificationEmail(). See Email Verification.Login
Signs a user in. The session is stored securely on the device and used for every request that follows.
lib/auth.dart
Dart
final user = await Koolbase.auth.login(
email: '[email protected]',
password: 'securepassword',
);
print(user.id); // User UUID
print(user.email);ContactNotVerifiedException
If the project requires a verified contact channel, login throws
ContactNotVerifiedException (ContactNotVerifiedError in React Native and on the web) when the account has no verified email, no verified phone, and no social sign-in. The credentials were correct — the project's policy refused — so route the user to resend-verification rather than asking them to re-check their password. Catch it separately from InvalidCredentialsException (InvalidCredentialsError). See Email Verification.Get current user
The signed-in user, or null when no one is signed in. It is read from the stored session, with no network call.
lib/auth.dart
Dart
final user = Koolbase.auth.currentUser;
if (user == null) {
// Not signed in — show the sign-in screen
Navigator.pushNamed(context, '/login');
} else {
print('Welcome, ${user.email}');
}Logout
Invalidates the current session token on the server and clears it from the device.
lib/auth.dart
Dart
await Koolbase.auth.logout();
// The session is revoked on the server and cleared from the deviceError handling
Each failure is its own type, so branch on the type rather than on a message.
lib/auth.dart
Dart
try {
await Koolbase.auth.login(email: email, password: password);
} on InvalidCredentialsException {
showError('Invalid email or password');
} on ContactNotVerifiedException {
showError('Please verify your email first');
} on UserDisabledException {
showError('Your account has been disabled');
} on AccountLockedException {
showError('Too many attempts. Check your email to unlock your account.');
} on KoolbaseAuthException catch (e) {
showError(e.message);
}