updateUser method

Future<GotrueUserResponse> updateUser(
  1. String jwt,
  2. UserAttributes attributes
)

Updates the user data.

Implementation

Future<GotrueUserResponse> updateUser(
  String jwt,
  UserAttributes attributes,
) async {
  try {
    final body = attributes.toJson();
    final headers = {...this.headers};
    headers['Authorization'] = 'Bearer $jwt';
    final options = FetchOptions(headers);
    final response = await _fetch.put('$url/user', body, options: options);
    if (response.error != null) {
      return GotrueUserResponse.fromResponse(response: response);
    } else {
      final user = User.fromJson(response.rawData as Map<String, dynamic>);
      return GotrueUserResponse.fromResponse(response: response, user: user);
    }
  } catch (e) {
    return GotrueUserResponse(error: GotrueError(e.toString()));
  }
}