login method

Future<ParseResponse> login({
  1. bool doNotSendInstallationID = false,
})

Logs a user in via Parse

Once a user is created using Parse.create and a username and password is provided, call this method to login. Set doNotSendInstallationID to 'true' in order to prevent the SDK from sending the installationID to the Server. This option is especially useful if you are running you application on web and you don't have permission to set 'X-Parse-Installation-Id' as an allowed header on your parse-server.

Implementation

Future<ParseResponse> login({bool doNotSendInstallationID = false}) async {
  forgetLocalSession();

  try {
    final Map<String, dynamic> queryParams = <String, String>{
      keyVarUsername: username!,
      keyVarPassword: password!
    };
    final String? installationId = await _getInstallationId();
    final Uri url = getSanitisedUri(_client, keyEndPointLogin);
    _saveChanges();
    final ParseNetworkResponse response = await _client.post(
      url.toString(),
      data: jsonEncode(queryParams),
      options: ParseNetworkOptions(headers: <String, String>{
        keyHeaderRevocableSession: '1',
        if (installationId != null && !doNotSendInstallationID)
          keyHeaderInstallationId: installationId,
      }),
    );

    return await _handleResponse(
        this, response, ParseApiRQ.login, _debug, parseClassName);
  } on Exception catch (e) {
    return handleException(e, ParseApiRQ.login, _debug, parseClassName);
  }
}