Skip to content

Commit 86f97a1

Browse files
authored
added doNotSendInstallationID parameter to user functions (#494)
* dont send X-Parse-Installation-Id on web * added doNotSendInstallationID parameter to user functions * use development branch in pubspec.yaml
1 parent 70daeaf commit 86f97a1

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

packages/dart/lib/src/objects/parse_user.dart

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
152152
/// After creating a new user via [Parse.create] call this method to register
153153
/// that user on Parse
154154
/// By setting [allowWithoutEmail] to `true`, you can sign up without setting an email
155-
Future<ParseResponse> signUp({bool allowWithoutEmail = false}) async {
155+
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
156+
/// This option is especially useful if you are running you application on web and you don't have permission to add 'X-Parse-Installation-Id' as an allowed header on your parse-server.
157+
Future<ParseResponse> signUp(
158+
{bool allowWithoutEmail = false,
159+
bool doNotSendInstallationID = false}) async {
156160
forgetLocalSession();
157161

158162
try {
@@ -161,7 +165,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
161165
return null;
162166
} else {
163167
assert(() {
164-
print('It is recommended to only allow user signUp with a ');
168+
print(
169+
'It is recommended to only allow user signUp with an email beeing set.');
165170
return true;
166171
}());
167172
}
@@ -175,7 +180,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
175180
await _client.post<String>(url.toString(),
176181
options: Options(headers: <String, String>{
177182
keyHeaderRevocableSession: '1',
178-
if (installationId != null)
183+
if (installationId != null && !doNotSendInstallationID)
179184
keyHeaderInstallationId: installationId,
180185
}),
181186
data: body);
@@ -191,7 +196,9 @@ class ParseUser extends ParseObject implements ParseCloneable {
191196
///
192197
/// Once a user is created using [Parse.create] and a username and password is
193198
/// provided, call this method to login.
194-
Future<ParseResponse> login() async {
199+
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
200+
/// 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.
201+
Future<ParseResponse> login({bool doNotSendInstallationID = false}) async {
195202
forgetLocalSession();
196203

197204
try {
@@ -207,7 +214,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
207214
url.toString(),
208215
options: Options(headers: <String, String>{
209216
keyHeaderRevocableSession: '1',
210-
if (installationId != null) keyHeaderInstallationId: installationId,
217+
if (installationId != null && !doNotSendInstallationID)
218+
keyHeaderInstallationId: installationId,
211219
}),
212220
);
213221

@@ -218,8 +226,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
218226
}
219227
}
220228

221-
// Logs in a user anonymously
222-
Future<ParseResponse> loginAnonymous() async {
229+
/// Logs in a user anonymously
230+
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
231+
/// This option is especially useful if you are running you application on web and you don't have permission to add 'X-Parse-Installation-Id' as an allowed header on your parse-server.
232+
Future<ParseResponse> loginAnonymous(
233+
{bool doNotSendInstallationID = false}) async {
223234
forgetLocalSession();
224235
try {
225236
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
@@ -230,7 +241,8 @@ class ParseUser extends ParseObject implements ParseCloneable {
230241
url.toString(),
231242
options: Options(headers: <String, String>{
232243
keyHeaderRevocableSession: '1',
233-
if (installationId != null) keyHeaderInstallationId: installationId,
244+
if (installationId != null && !doNotSendInstallationID)
245+
keyHeaderInstallationId: installationId,
234246
}),
235247
data: jsonEncode(<String, dynamic>{
236248
'authData': <String, dynamic>{
@@ -247,23 +259,30 @@ class ParseUser extends ParseObject implements ParseCloneable {
247259
}
248260
}
249261

250-
// Logs in a user using a service
251-
static Future<ParseResponse> loginWith(
252-
String provider, Object authData) async {
262+
/// Logs in a user using a service
263+
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
264+
/// This option is especially useful if you are running you application on web and you don't have permission to add 'X-Parse-Installation-Id' as an allowed header on your parse-server.
265+
static Future<ParseResponse> loginWith(String provider, Object authData,
266+
{bool doNotSendInstallationID = false}) async {
253267
final ParseUser user = ParseUser.createUser();
254-
final ParseResponse response = await user._loginWith(provider, authData);
268+
final ParseResponse response = await user._loginWith(provider, authData,
269+
doNotSendInstallationID: doNotSendInstallationID);
255270
return response;
256271
}
257272

258-
Future<ParseResponse> _loginWith(String provider, Object authData) async {
273+
/// Set [doNotSendInstallationID] to 'true' in order to prevent the SDK from sending the installationID to the Server.
274+
/// This option is especially useful if you are running you application on web and you don't have permission to add 'X-Parse-Installation-Id' as an allowed header on your parse-server.
275+
Future<ParseResponse> _loginWith(String provider, Object authData,
276+
{bool doNotSendInstallationID = false}) async {
259277
try {
260278
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
261279
final String installationId = await _getInstallationId();
262280
final Response<String> response = await _client.post<String>(
263281
url.toString(),
264282
options: Options(headers: <String, String>{
265283
keyHeaderRevocableSession: '1',
266-
if (installationId != null) keyHeaderInstallationId: installationId,
284+
if (installationId != null && !doNotSendInstallationID)
285+
keyHeaderInstallationId: installationId,
267286
}),
268287
data: jsonEncode(<String, dynamic>{
269288
'authData': <String, dynamic>{provider: authData}

packages/flutter/pubspec.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ dependencies:
1010
flutter:
1111
sdk: flutter
1212

13-
parse_server_sdk: ^2.0.0
13+
parse_server_sdk:
14+
git:
15+
url: git://github.com/parse-community/Parse-SDK-Flutter.git
16+
ref: development
17+
path: packages/dart
1418

1519
# Networking
1620
dio: ^3.0.10

0 commit comments

Comments
 (0)