getCurrentUser method

Future<AppUser> getCurrentUser()

Fetch the current authenticated user's data from the server

Example:

final user = await db.auth.getCurrentUser();
print('Current user: ${user.email}');

Implementation

Future<AppUser> getCurrentUser() async {
  if (_token == null) {
    throw Exception('User is not authenticated');
  }

  final response = await _request<Map<String, dynamic>>(
    'GET',
    '/auth-collections/user',
  );

  if (response.isEmpty) {
    throw Exception('Failed to fetch current user');
  }

  _user = AppUser.fromJson(response);
  await setUser(_user!);
  return _user!;
}