Skip to content

Commit e7dd150

Browse files
mregandlaphillwiggins
authored andcommitted
Setting installationId in _Session object during sign-up (#293)
Excellent work!
1 parent 44e30f6 commit e7dd150

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/src/base/parse_constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const String keyHeaderContentType = 'Content-Type';
4949
const String keyHeaderContentTypeJson = 'application/json';
5050
const String keyHeaderMasterKey = 'X-Parse-Master-Key';
5151
const String keyHeaderClientKey = 'X-Parse-Client-Key';
52+
const String keyHeaderInstallationId = 'X-Parse-Installation-Id';
5253

5354
// URL params
5455
const String keyParamSessionToken = 'sessionToken';

lib/src/objects/parse_user.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
3333

3434
@override
3535
dynamic clone(Map<String, dynamic> map) =>
36-
ParseUser.clone(map)
37-
..fromJson(map);
36+
ParseUser.clone(map)..fromJson(map);
3837

3938
static const String keyEmailVerified = 'emailVerified';
4039
static const String keyUsername = 'username';
@@ -141,9 +140,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
141140
final Uri url = getSanitisedUri(_client, '$path');
142141
final String body = json.encode(bodyData);
143142
_saveChanges();
143+
final String installationId = await _getInstallationId();
144144
final Response response = await _client.post(url,
145145
headers: <String, String>{
146146
keyHeaderRevocableSession: '1',
147+
if (installationId != null) keyHeaderInstallationId: installationId,
147148
},
148149
body: body);
149150

@@ -185,10 +186,12 @@ class ParseUser extends ParseObject implements ParseCloneable {
185186
try {
186187
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
187188
final Uuid uuid = Uuid();
189+
final String installationId = await _getInstallationId();
188190

189191
final Response response = await _client.post(url,
190192
headers: <String, String>{
191193
keyHeaderRevocableSession: '1',
194+
if (installationId != null) keyHeaderInstallationId: installationId,
192195
},
193196
body: jsonEncode(<String, dynamic>{
194197
'authData': <String, dynamic>{
@@ -215,9 +218,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
215218
Future<ParseResponse> _loginWith(String provider, Object authData) async {
216219
try {
217220
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
221+
final String installationId = await _getInstallationId();
218222
final Response response = await _client.post(url,
219223
headers: <String, String>{
220224
keyHeaderRevocableSession: '1',
225+
if (installationId != null) keyHeaderInstallationId: installationId,
221226
},
222227
body: jsonEncode(<String, dynamic>{
223228
'authData': <String, dynamic>{provider: authData}
@@ -396,4 +401,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
396401
}
397402

398403
static ParseUser _getEmptyUser() => ParseUser(null, null, null);
404+
405+
static Future<String> _getInstallationId() async {
406+
final ParseInstallation parseInstallation =
407+
await ParseInstallation.currentInstallation();
408+
return parseInstallation?.installationId;
409+
}
399410
}

0 commit comments

Comments
 (0)