updateUser method

Future<UserResponse> updateUser(
  1. UserAttributes attributes, {
  2. String? emailRedirectTo,
})

Updates user data, if there is a logged in user.

Implementation

Future<UserResponse> updateUser(
  UserAttributes attributes, {
  String? emailRedirectTo,
}) async {
  final accessToken = currentSession?.accessToken;
  if (accessToken == null) {
    throw AuthException('Not logged in.');
  }

  final body = attributes.toJson();
  final options = GotrueRequestOptions(
    headers: _headers,
    body: body,
    jwt: accessToken,
    redirectTo: emailRedirectTo,
  );
  final response = await _fetch.request('$_url/user', RequestMethodType.put,
      options: options);
  final userResponse = UserResponse.fromJson(response);

  _currentUser = userResponse.user;
  _currentSession = currentSession?.copyWith(user: userResponse.user);
  notifyAllSubscribers(AuthChangeEvent.userUpdated);

  return userResponse;
}