tokenIsValid function

Future<bool> tokenIsValid({
  1. required String accessToken,
})

Implementation

Future<bool> tokenIsValid({
  required String accessToken,
})async{
  //Verify token validity
  late List<FileSystemEntity> files;
  if(await authFolder.exists()){
    files = await authFolder.list().toList();
  }else{
    files = [];
  }
  Account? storedAccount;
  for(int i = 0; (i < files.length) && storedAccount == null; i++){
    File accountFile = File(files[i].path);
    String json = await accountFile.readAsString();
    //File uuid
    String fileUUID = files[i].path.substring(authFolder.path.length + 1, files[i].path.lastIndexOf(".json"));
    Account thisAccount = Account.parse(fileUUID, json);
    for(int a = 0; (a < thisAccount.accessTokens.length) && storedAccount == null; a++){
      if(thisAccount.accessTokens[a] == accessToken){
        storedAccount = thisAccount;
      }
    }
  }
  if(storedAccount != null){
    return true;
  }else{
    return false;
  }
}