setSession method
Hands over the session obtained by the app's sign-in flow.
Pending profile changes start uploading right away, and so do pending activities when ActivityStoreConfig.syncEnabled is true.
Parameters
accessToken: The access token.refreshToken: The refresh token, used to renew the access token.expiresInSec: The lifetime of the access token in seconds.onComplete: Called with GemError.success, or GemError.invalidInput when a token is empty.
Returns
- The ProgressListener of the call, or null when it could not start.
Implementation
ProgressListener? setSession({
required String accessToken,
required String refreshToken,
required int expiresInSec,
void Function(GemError error)? onComplete,
}) {
final EventDrivenProgressListener progressListener =
EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(
progressListener.id,
progressListener,
);
progressListener.registerOnCompleteWithData((
int err,
String hint,
Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(progressListener.id);
onComplete?.call(GemErrorExtension.fromCode(err));
});
final OperationResult resultString = objectMethod(
pointerId,
'ActivityStore',
'setSession',
args: <String, dynamic>{
'accessToken': accessToken,
'refreshToken': refreshToken,
'expiresInSec': expiresInSec,
'listener': progressListener.id,
},
logPrivacyLevel: LogPrivacyLevel.hideArgumentValues,
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
onComplete?.call(errorCode);
return null;
}
return progressListener;
}