Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Auth — Flutter SDK

final result = await bunbase.auth.register('alice@example.com', 'secret');
// result.user is now set; tokens persisted automatically
final result = await bunbase.auth.login('alice@example.com', 'secret');
switch (result) {
case Authenticated(:final value):
print('Logged in as ${value.user.email}');
case TotpRequired(:final challenge):
// Prompt user for TOTP code, then:
await bunbase.auth.verifyTotp(challenge.totpToken, userCode);
}
// Send the email:
await bunbase.auth.requestMagicLink('alice@example.com');
// After user clicks the link, verify the token from the URL:
await bunbase.auth.verifyMagicLink(tokenFromUrl);
// Invalidates the current session on the server:
await bunbase.auth.logout();
// Invalidates all sessions:
await bunbase.auth.logoutAll();
// Read snapshot:
final user = bunbase.auth.user; // AuthUser?
// Reactive (recommended):
ValueListenableBuilder<AuthUser?>(
valueListenable: bunbase.auth.currentUser,
builder: (_, user, __) => user == null ? Login() : Home(),
)
// Fetch fresh from server:
final fresh = await bunbase.auth.me();
final updated = await bunbase.auth.updateMe({'displayName': 'Alice'});
await bunbase.auth.forgotPassword('alice@example.com');
// After user clicks the email link:
await bunbase.auth.resetPassword(tokenFromUrl, 'newPassword123');
await bunbase.auth.verifyEmail(tokenFromUrl);
// Resend verification email:
await bunbase.auth.resendVerification();
// Check status:
final enabled = await bunbase.auth.getTotpStatus();
// Setup:
final setup = await bunbase.auth.setupTotp();
print(setup.qrCodeUrl); // show in QR widget
// Enable after user scans:
await bunbase.auth.enableTotp(userCode);
// Disable:
await bunbase.auth.disableTotp(userCode);
// List:
final keys = await bunbase.auth.listApiKeys();
// Create:
final created = await bunbase.auth.createApiKey('My App Key');
print(created.key); // shown once — save it
// Revoke:
await bunbase.auth.revokeApiKey(keyId);
await bunbase.auth.deleteAccount(currentPassword);