antoniopresto / react-native-local-mongodb

react-native local mongodb storage.
MIT License
303 stars 66 forks source link

Support for asynchronous encrypt/decrypt functions in afterSerialization and beforeSerialization #69

Open jwh-hutchison opened 3 years ago

jwh-hutchison commented 3 years ago

inside my datastore configuration:

  afterSerialization: async (data) => {
    const payload = await data;
    console.log('E1: ', payload);

    const encrypted = await encryptData(payload);
    console.log('E2: ', encrypted);
    return encrypted;
  },
  beforeDeserialization: async (data) => {
    const payload = await data;
    console.log('D1: ', payload);

    const decrypted = await decryptData(payload);
    console.log('D2: ', decrypted);
    return decrypted;
  },

gives me:

Error: beforeDeserialization is not the reverse of afterSerialization, cautiously refusing to start NeDB to prevent dataloss
E1:  W
E2:  FuoRfmMKynBFuOOLrEBhSw==
D1:  FuoRfmMKynBFuOOLrEBhSw==
D2:  W

it appears that the encryption/decryption will not work if they are asynchronous functions, it would be good to support this because all the good AES crypto libraries on react-native are asynchronous.