deleteSession method
- SessionId? id,
- UserPassword? password,
- ConfirmationCode? code,
- bool force = false,
- bool keepData = true,
Deletes Session with the provided id, if any, or otherwise Session
of the active MyUser.
Returns the path of the authentication page.
If force is true, then the current Credentials will be revoked
unilaterally and immediately.
Implementation
Future<String?> deleteSession({
SessionId? id,
UserPassword? password,
ConfirmationCode? code,
bool force = false,
bool keepData = true,
}) async {
Log.debug(
'deleteSession($id, password: ${password?.obscured}, code: $code, force: $force, keepData: $keepData)',
'$runtimeType',
);
if (id != null) {
await _authRepository.deleteSession(
id: id,
password: password,
code: code,
);
return null;
}
status.value = RxStatus.empty();
final Future<void> Function({bool keepData})? logoutCallback = onLogout;
Future<void> handleCallbacks() async {
if (logoutCallback != null) {
Log.debug('Invoking `onLogout(keepData: $keepData)`', '$runtimeType');
try {
await logoutCallback(keepData: keepData);
} catch (e) {
Log.debug('Unable to invoke `onLogout()`: $e', '$runtimeType');
}
onLogout = null;
hasCalls = null;
}
}
if (force) {
if (userId != null) {
_authRepository.removeAccount(userId!);
}
_unauthorized();
await handleCallbacks();
return Routes.auth;
}
return await WebUtils.protect(() async {
try {
await _authRepository.deleteSession();
} catch (e) {
Log.warning('Failed to delete `Session`: $e');
}
_unauthorized();
await handleCallbacks();
return Routes.auth;
});
}