pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.63k stars 1.06k forks source link

React-native WebSQL crypto.getRandomValues #3570

Closed Acetyld closed 2 years ago

Acetyld commented 2 years ago

Schermafbeelding 2021-12-13 om 10 17 35

Using latest react native, together with the react-native example. I keep getting crypto.getRandomValues error

import schema from './Schema';
import {createRxDatabase} from 'rxdb';
import {addPouchPlugin, getRxStoragePouch} from 'rxdb/plugins/pouchdb';
import SQLite from 'react-native-sqlite-2';
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite';
const SQLiteAdapter = SQLiteAdapterFactory(SQLite);

addPouchPlugin(SQLiteAdapter);
addPouchPlugin(require('pouchdb-adapter-http'));
const syncURL = 'http://localhost:10102/'; // Replace localhost with a public ip address!
const dbName = 'heroesreactdatabase1';
const initialize = async () => {
  let db;
  try {
    console.log('Initializing database...');
    db = await createRxDatabase({
      name: dbName,
      storage: getRxStoragePouch('react-native-sqlite'),
      multiInstance: false,
      ignoreDuplicate: true,
    });
    console.log('Database initialized!');
  } catch (err) {
    console.log('ERROR CREATING DATABASE', err);
  }
  console.log('Adding hero collection...');
  try {
    const heroCollection = await db.addCollections({
      heroes: {
        schema: schema,
      },
    });
    heroCollection.sync({
      remote: syncURL + dbName + '/',
      options: {
        live: true,
        retry: true,
      },
    });
  } catch (err) {
    console.log('ERROR CREATING COLLECTION', err);
  }

  return db;
};

export default initialize;

{ "name": "RXDBExample", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "base-64": "^1.0.0", "events": "^3.3.0", "pouchdb-adapter-http": "^7.2.2", "pouchdb-adapter-react-native-sqlite": "^3.0.1", "random-token": "^0.0.8", "react": "17.0.2", "react-native": "0.66.4", "react-native-sqlite-2": "^3.5.0", "rxdb": "^10.5.4", "rxjs": "^7.4.0" }, "devDependencies": { "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.6.3", "eslint": "7.14.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.66.2", "react-test-renderer": "17.0.2" }, "jest": { "preset": "react-native" } }

Acetyld commented 2 years ago

I installed import 'react-native-get-random-values', followed the UUID docs for react-native. This seems to have fixed the issue. Weird this is not documented anywhere?

pubkey commented 2 years ago

Do you use encryption in the schema?

Acetyld commented 2 years ago

Hello

No encryption anywhere. But installing the package fixed everything

pubkey commented 2 years ago

Your problem looks like a pouchdb bug. You should reproduce it with plain pouchdb and create an issue there.