saveSession method
Saves the given session
to the database.
If merge
is true, the session will be updated with the new values
while preserving the existing ones. The sensitive fields will be encrypted
before saving:
clientId
defaultAttributes.customerAccount
defaultAttributes.customerEmail
defaultAttributes.customerMobile
defaultAttributes.customerClientId
defaultAttributes.customerBirthday
If merge
is false, the session will be saved as a new entry.
The session
parameter is the session data to be saved.
The merge
parameter determines whether to merge the session data with
existing data or to save it as a new entry.
Throws an exception if the save operation fails.
Implementation
Future<void> saveSession(
InternalSession session, {
required bool merge,
}) async {
if (merge) {
session.freshInstall = false;
if (session.clientId != null) {
session.clientId = encrypt(session.clientId!);
}
if (session.defaultAttributes.customerAccount != null) {
session.defaultAttributes.customerAccount =
encrypt(session.defaultAttributes.customerAccount!);
}
if (session.defaultAttributes.customerEmail != null) {
session.defaultAttributes.customerEmail =
encrypt(session.defaultAttributes.customerEmail!);
}
if (session.defaultAttributes.customerMobile != null) {
session.defaultAttributes.customerMobile =
encrypt(session.defaultAttributes.customerMobile!);
}
if (session.defaultAttributes.customerClientId != null) {
session.defaultAttributes.customerClientId =
encrypt(session.defaultAttributes.customerClientId!);
}
if (session.defaultAttributes.customerBirthday != null) {
session.defaultAttributes.customerBirthday =
encrypt(session.defaultAttributes.customerBirthday!);
}
}
await _doc.set(session.toJson(), SetOptions(merge: merge));
}