getUserSession method
Implementation
Future<CubeSession?> getUserSession(
bool isSessionRequired,
bool isUserRequired,
) async {
if (_createSessionCompleter != null) {
return _createSessionCompleter!.future;
}
_createSessionCompleter = Completer<CubeSession?>();
Future<CubeSession?>? createSessionFeature;
if (isActiveSessionValid()) {
createSessionFeature = Future.value(activeSession);
} else if (isSessionRequired) {
if (isUserRequired && CubeSettings.instance.onSessionRestore != null) {
createSessionFeature = CubeSettings.instance.onSessionRestore!.call();
} else {
createSessionFeature = createSession();
}
}
(createSessionFeature ?? Future.value(null)).then((cubeSession) {
_createSessionCompleter?.complete(cubeSession);
}).catchError((onError) {
_createSessionCompleter?.completeError(onError);
});
return _createSessionCompleter!.future.whenComplete(() {
_createSessionCompleter = null;
});
}