Fix: Remove synced codes on logout

This commit is contained in:
Neeraj Gupta 2023-04-04 16:06:51 +05:30
parent 873da725f9
commit abf4afe76e
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 14 additions and 0 deletions

View file

@ -5,15 +5,18 @@ import 'package:flutter/material.dart';
@immutable
class LocalAuthEntity {
final int generatedID;
// id can be null if a code has been scanned locally but it's yet to be
// synced with the remote server.
final String? id;
final String encryptedData;
final String header;
// createdAt and updateAt will be equal to local time of creation or updation
// till remote sync is completed.
final int createdAt;
final int updatedAt;
// shouldSync indicates that the entry was locally created or updated. The
// app should try to sync it to the server during next sync
final bool shouldSync;

View file

@ -134,7 +134,11 @@ class AuthenticatorService {
_logger.info("local push completed");
Bus.instance.fire(CodesUpdatedEvent());
} on UnauthorizedError {
if ((await _db.removeSyncedData()) > 0) {
Bus.instance.fire(CodesUpdatedEvent());
}
debugPrint("Firing logout event");
Bus.instance.fire(TriggerLogoutEvent());
} catch (e) {
_logger.severe("Failed to sync with remote", e);

View file

@ -135,6 +135,13 @@ class AuthenticatorDB {
return _convertRows(rows);
}
// removeSyncedData will remove all the data which is synced with the server
Future<int> removeSyncedData() async {
final db = await instance.database;
return await db
.delete(entityTable, where: 'shouldSync = ?', whereArgs: [0]);
}
// deleteByID will prefer generated id if both ids are passed during deletion
Future<void> deleteByIDs({List<int>? generatedIDs, List<String>? ids}) async {
final db = await instance.database;