inviteUserByEmail method

Future<GotrueJsonResponse> inviteUserByEmail(
  1. String email, {
  2. AuthOptions? options,
})

Sends an invite link to an email address.

Implementation

Future<GotrueJsonResponse> inviteUserByEmail(
  String email, {
  AuthOptions? options,
}) async {
  try {
    final body = {'email': email};
    final fetchOptions = FetchOptions(headers);
    final urlParams = [];
    if (options?.redirectTo != null) {
      final encodedRedirectTo = Uri.encodeComponent(options!.redirectTo!);
      urlParams.add('redirect_to=$encodedRedirectTo');
    }
    final queryString = urlParams.isNotEmpty ? '?${urlParams.join('&')}' : '';
    final response = await _fetch.post(
      '$url/invite$queryString',
      body,
      options: fetchOptions,
    );
    if (response.error != null) {
      return GotrueJsonResponse.fromResponse(response: response);
    } else {
      return GotrueJsonResponse.fromResponse(
        response: response,
        data: response.rawData as Map<String, dynamic>?,
      );
    }
  } catch (e) {
    return GotrueJsonResponse(error: GotrueError(e.toString()));
  }
}