mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-18 17:47:32 +00:00
Enable download-api-helper to be started for existing user
This commit is contained in:
parent
b567cd3006
commit
22aaeedd3b
@ -2,19 +2,19 @@
|
|||||||
This script creates 3 new objects into a new realm. These are objects are validated to exists by the download api tests.
|
This script creates 3 new objects into a new realm. These are objects are validated to exists by the download api tests.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
console.log("download-api-helper started");
|
||||||
const username = process.argv[2];
|
const username = process.argv[2];
|
||||||
const realmName = process.argv[3];
|
const realmName = process.argv[3];
|
||||||
const realmModule = process.argv[4];
|
const realmModule = process.argv[4];
|
||||||
|
|
||||||
var Realm = require(realmModule);
|
var Realm = require(realmModule);
|
||||||
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
|
|
||||||
if (error) {
|
function createObjects(user) {
|
||||||
console.log(error);
|
|
||||||
process.exit(-2);
|
|
||||||
} else {
|
|
||||||
const config = {
|
const config = {
|
||||||
sync: { user, url: `realm://localhost:9080/~/${realmName}`, error: err => console.log(err) },
|
sync: { user,
|
||||||
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
|
error: err => console.log(err)
|
||||||
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,6 +29,22 @@ Realm.Sync.User.register('http://localhost:9080', username, 'password', (error,
|
|||||||
console.log("Dogs count " + realm.objects('Dog').length);
|
console.log("Dogs count " + realm.objects('Dog').length);
|
||||||
setTimeout(() => process.exit(0), 3000);
|
setTimeout(() => process.exit(0), 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => {
|
||||||
|
if (error) {
|
||||||
|
const registrationError = JSON.stringify(error);
|
||||||
|
Realm.Sync.User.login('http://localhost:9080', username, 'password', (err, loggedUser) => {
|
||||||
|
if (err) {
|
||||||
|
const loginError = JSON.stringify(err);
|
||||||
|
console.error("download-api-helper failed:\n User.register() error:\n" + registrationError + "\n User.login() error:\n" + loginError);
|
||||||
|
process.exit(-2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
createObjects(loggedUser);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
createObjects(registeredUser);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user