Skip to content

Setting installationId in _Session object during sign-up #293

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
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 @@ -49,6 +49,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
15 changes: 13 additions & 2 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class ParseUser extends ParseObject implements ParseCloneable {

@override
dynamic clone(Map<String, dynamic> map) =>
ParseUser.clone(map)
..fromJson(map);
ParseUser.clone(map)..fromJson(map);

static const String keyEmailVerified = 'emailVerified';
static const String keyUsername = 'username';
Expand Down Expand Up @@ -141,9 +140,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
final Uri url = getSanitisedUri(_client, '$path');
final String body = json.encode(bodyData);
_saveChanges();
final String installationId = await _getInstallationId();
final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
if (installationId != null) keyHeaderInstallationId: installationId,
},
body: body);

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

final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
if (installationId != null) keyHeaderInstallationId: installationId,
},
body: jsonEncode(<String, dynamic>{
'authData': <String, dynamic>{
Expand All @@ -215,9 +218,11 @@ class ParseUser extends ParseObject implements ParseCloneable {
Future<ParseResponse> _loginWith(String provider, Object authData) async {
try {
final Uri url = getSanitisedUri(_client, '$keyEndPointUsers');
final String installationId = await _getInstallationId();
final Response response = await _client.post(url,
headers: <String, String>{
keyHeaderRevocableSession: '1',
if (installationId != null) keyHeaderInstallationId: installationId,
},
body: jsonEncode(<String, dynamic>{
'authData': <String, dynamic>{provider: authData}
Expand Down Expand Up @@ -396,4 +401,10 @@ class ParseUser extends ParseObject implements ParseCloneable {
}

static ParseUser _getEmptyUser() => ParseUser(null, null, null);

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