Auth — Flutter SDK
Register
Section titled “Register”final result = await bunbase.auth.register('alice@example.com', 'secret');// result.user is now set; tokens persisted automaticallyfinal 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);}Magic link
Section titled “Magic link”// 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);Logout
Section titled “Logout”// Invalidates the current session on the server:await bunbase.auth.logout();
// Invalidates all sessions:await bunbase.auth.logoutAll();Current user
Section titled “Current user”// 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();Update profile metadata
Section titled “Update profile metadata”final updated = await bunbase.auth.updateMe({'displayName': 'Alice'});Password reset
Section titled “Password reset”await bunbase.auth.forgotPassword('alice@example.com');
// After user clicks the email link:await bunbase.auth.resetPassword(tokenFromUrl, 'newPassword123');Email verification
Section titled “Email verification”await bunbase.auth.verifyEmail(tokenFromUrl);
// Resend verification email:await bunbase.auth.resendVerification();TOTP / 2FA
Section titled “TOTP / 2FA”// 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);API keys
Section titled “API keys”// 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);Delete account
Section titled “Delete account”await bunbase.auth.deleteAccount(currentPassword);