Skip to content

Setting installationId in _Session object during sign-up #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const String keyHeaderContentType = 'Content-Type';
const String keyHeaderContentTypeJson = 'application/json';
const String keyHeaderMasterKey = 'X-Parse-Master-Key';
const String keyHeaderClientKey = 'X-Parse-Client-Key';
const String keyHeaderInstallationId = 'X-Parse-Installation-Id';

// URL params
const String keyParamSessionToken = 'sessionToken';
Expand Down
41 changes: 30 additions & 11 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
bodyData[keyVarPassword] = password;
bodyData[keyVarUsername] = username;
final Uri url = getSanitisedUri(_client, '$path');
final Map<String, String> headers = <String, String>{
keyHeaderRevocableSession: '1',
};
final String installationId = await _getInstallationId();
if (installationId != null) {
headers[keyHeaderInstallationId] = installationId;
}
final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
},
body: json.encode(bodyData));
headers: headers, body: json.encode(bodyData));

return _handleResponse(
this, response, ParseApiRQ.signUp, _debug, className);
Expand Down Expand Up @@ -174,11 +178,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
try {
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
final Uuid uuid = Uuid();

final Map<String, String> headers = <String, String>{
keyHeaderRevocableSession: '1',
};
final String installationId = await _getInstallationId();
if (installationId != null) {
headers[keyHeaderInstallationId] = installationId;
}
final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
},
headers: headers,
body: jsonEncode(<String, dynamic>{
'authData': <String, dynamic>{
'anonymous': <String, dynamic>{'id': uuid.v4()}
Expand All @@ -203,10 +211,15 @@ class ParseUser extends ParseObject implements ParseCloneable {
Future<ParseResponse> _loginWith(String provider, Object authData) async {
try {
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
final Map<String, String> headers = <String, String>{
keyHeaderRevocableSession: '1',
};
final String installationId = await _getInstallationId();
if (installationId != null) {
headers[keyHeaderInstallationId] = installationId;
}
final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
},
headers: headers,
body: jsonEncode(<String, dynamic>{
'authData': <String, dynamic>{provider: authData}
}));
Expand All @@ -218,6 +231,12 @@ class ParseUser extends ParseObject implements ParseCloneable {
}
}

static Future<String> _getInstallationId() async {
final ParseInstallation parseInstallation =
await ParseInstallation.currentInstallation();
return parseInstallation?.installationId;
}

/// Sends a request to delete the sessions token from the
/// server. Will also delete the local user data unless
/// deleteLocalUserData is false.
Expand Down