addOrUpdateToken method
Implementation
Future<void> addOrUpdateToken(
String deviceId,
String refreshDeviceId,
String token,
int fetchTime,
String? anonTime,
String? userId
) async {
Map<String, dynamic> tokens = {};
final tokenFileContent = await AppticsDataStore.getFileContents(FileType.bearerInfo);
if (tokenFileContent != null) {
tokens = jsonDecode(tokenFileContent);
}
var tokenForDevice = tokens.putIfAbsent(deviceId, () => {}) as Map<dynamic, dynamic>;
tokenForDevice["token"] = token;
tokenForDevice["refreshDeviceId"] = refreshDeviceId;
tokenForDevice["fetchtime"] = fetchTime;
if (anonTime != null) {
tokenForDevice["anontime"] = anonTime;
}
if (userId != null) {
var users = tokenForDevice.putIfAbsent("users", () => []) as List<dynamic>;
users.add(userId);
}
await AppticsDataStore.writeContent(jsonEncode(tokens), FileType.bearerInfo);
}