checkIfJwtIsActive method

  1. @override
Future<bool> checkIfJwtIsActive(
  1. JWTPayloadModel jwt
)
override

Implementation

@override
Future<bool> checkIfJwtIsActive(JWTPayloadModel jwt) async {
  var authUpdates = dbService.mongoDbController
      .collection(app.authSettings.authUpdatesCollName);
  var doc = await authUpdates.doc(jwt.id).getData();
  String? passwordValue = doc?[ModelFields.password];
  if (passwordValue == null) {
    // this means that the password was never updates
    return true;
  }
  // here check if the password was updated after this jwt was created
  DateTime? passwordChangeDate = DateTime.tryParse(passwordValue);
  DateTime? jwtCreatedAt = DateTime.tryParse(jwt.createdAt);
  if (passwordChangeDate == null || jwtCreatedAt == null) {
    throw InvalidDateValue();
  }
  bool valid = jwtCreatedAt.isAfter(passwordChangeDate);
  return valid;
}