login method
Authenticate a user with email and password
Example:
await db.auth.login('user@example.com', 'password123');
print('Logged in as: ${db.auth.getUser()?.email}');
Implementation
Future<void> login(String email, String password) async {
final response = await _request<Map<String, dynamic>>(
'POST',
'/auth-collections/login',
body: {'email': email, 'password': password},
useDataKey: false,
);
final tokenResponse = TokenResponse.fromJson(response);
_token = tokenResponse.accessToken;
await setToken(_token!);
if (response['user'] != null) {
_user = AppUser.fromJson(response['user']);
await setUser(_user!);
} else {
await getCurrentUser();
}
// Trigger login callback
if (_user != null) {
_callbacks.onLogin?.call(_user!, _token!);
}
}