Skip to content

Commit 836bee0

Browse files
mregandlaphillwiggins
authored andcommitted
Setting installationId in _Session object during sign-up (#136)
* Setting installationId in _Session object during sign-up * Setting installationId in _Session object during sign-up - Added null check
1 parent 407cf5f commit 836bee0

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

lib/src/base/parse_constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const String keyHeaderContentType = 'Content-Type';
4444
const String keyHeaderContentTypeJson = 'application/json';
4545
const String keyHeaderMasterKey = 'X-Parse-Master-Key';
4646
const String keyHeaderClientKey = 'X-Parse-Client-Key';
47+
const String keyHeaderInstallationId = 'X-Parse-Installation-Id';
4748

4849
// URL params
4950
const String keyParamSessionToken = 'sessionToken';

lib/src/objects/parse_user.dart

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
126126
bodyData[keyVarPassword] = password;
127127
bodyData[keyVarUsername] = username;
128128
final Uri url = getSanitisedUri(_client, '$path');
129+
final Map<String, String> headers = <String, String>{
130+
keyHeaderRevocableSession: '1',
131+
};
132+
final String installationId = await _getInstallationId();
133+
if (installationId != null) {
134+
headers[keyHeaderInstallationId] = installationId;
135+
}
129136
final Response response = await _client.post(url,
130-
headers: <String, String>{
131-
keyHeaderRevocableSession: '1',
132-
},
133-
body: json.encode(bodyData));
137+
headers: headers, body: json.encode(bodyData));
134138

135139
return _handleResponse(
136140
this, response, ParseApiRQ.signUp, _debug, className);
@@ -174,11 +178,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
174178
try {
175179
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
176180
final Uuid uuid = Uuid();
177-
181+
final Map<String, String> headers = <String, String>{
182+
keyHeaderRevocableSession: '1',
183+
};
184+
final String installationId = await _getInstallationId();
185+
if (installationId != null) {
186+
headers[keyHeaderInstallationId] = installationId;
187+
}
178188
final Response response = await _client.post(url,
179-
headers: <String, String>{
180-
keyHeaderRevocableSession: '1',
181-
},
189+
headers: headers,
182190
body: jsonEncode(<String, dynamic>{
183191
'authData': <String, dynamic>{
184192
'anonymous': <String, dynamic>{'id': uuid.v4()}
@@ -203,10 +211,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
203211
Future<ParseResponse> _loginWith(String provider, Object authData) async {
204212
try {
205213
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
214+
final Map<String, String> headers = <String, String>{
215+
keyHeaderRevocableSession: '1',
216+
};
217+
final String installationId = await _getInstallationId();
218+
if (installationId != null) {
219+
headers[keyHeaderInstallationId] = installationId;
220+
}
206221
final Response response = await _client.post(url,
207-
headers: <String, String>{
208-
keyHeaderRevocableSession: '1',
209-
},
222+
headers: headers,
210223
body: jsonEncode(<String, dynamic>{
211224
'authData': <String, dynamic>{provider: authData}
212225
}));
@@ -218,6 +231,12 @@ class ParseUser extends ParseObject implements ParseCloneable {
218231
}
219232
}
220233

234+
static Future<String> _getInstallationId() async {
235+
final ParseInstallation parseInstallation =
236+
await ParseInstallation.currentInstallation();
237+
return parseInstallation?.installationId;
238+
}
239+
221240
/// Sends a request to delete the sessions token from the
222241
/// server. Will also delete the local user data unless
223242
/// deleteLocalUserData is false.

0 commit comments

Comments
 (0)