Reputation: 41
Every time I erase/restart my simulation I get the above error message. Is there a way to insert a dummy user object that allows me to parse through the 'const' and get to the actual login?
import React from 'react';
import { StyleSheet, AppRegistry, TextInput, Text, View, Alert, } from 'react-native';
import Realm from 'realm';
logBookSchema = {schema: [{
name: 'LogBook',
properties: {
logNum: 'int',
},
}]
}
class LogBook extends Realm.Object {}
const realm = new Realm({sync: {user: Realm.Sync.User.current, url: 'realm://localhost:9080/~/logbook',error: err => alert(err)},logBookSchema});
export default class App extends React.Component {
render() {
Realm.Sync.User.login('http://localhost:9080', '[email protected]', 'test').then (user => {
Realm.open({logBookSchema, sync: {user: user, url: 'realm://localhost:9080/~/logbook',error: err => alert(err)}});
});
return (
<View><Text></Text><Text>Logged in</Text></View>
)
}
}
Upvotes: 3
Views: 2935
Reputation: 41
Finally left the valley of doom. Here my approach:
export default class LoginScreen extends React.Component {
constructor(props) {
super(props);
this.state = { realm: null };
}
componentWillMount() {
Realm.Sync.User.login('http://192.168.2.105:9080', '[email protected]', 'test')
.then (user => {
Realm.open({schema: [LogBook],
sync: {user: user, url: 'realm://192.168.2.105:9080/~/logbook',error: err => alert(err)}
})
.then(realm => {
this.setState({ realm });
});
});
}
render() {
if (!this.state.realm) {return (
<View><Text></Text><Text>Loading</Text></View>
)}
else {
return (
<MyApp />
);
}
}
}
Upvotes: 1