我尝试初始化一个Stitch默认应用程序客户端,但是在初始化客户端时总是会出现错误。
这是我的代码:
import React from 'react';
import {View, Text, SafeAreaView} from 'react-native';
import {Stitch, AnonymousCredential} from 'mongodb-stitch-react-native-sdk';
class App extends React.Component {
render() {
return (
<SafeAreaView>
<View>
<Text>Stitch Test</Text>
</View>
</SafeAreaView>
);
}
async componentDidMount() {
console.log('=> App/componentDidMount');
await this._loadClient();
}
_loadClient() {
console.log('=> App/_loadClient');
Stitch.initializeDefaultAppClient('tuto - nbmzq').then(client => {
if (client.auth.isLoggedIn) {
client.auth
.loginWithCredential(new AnonymousCredential())
.then(user => {
console.log('Successfully logged in as user ${user.id}');
})
.catch(err => {
console.log(err);
});
} else {
console.log(client);
console.log('Error initialize Client'); // Always fall here
}
});
}
}
export default App;应用Id存在,我可以在MongoDB网站上连接它。我哪里出问题了?
谢谢++埃里克
发布于 2019-12-06 18:09:25
在Stitch.initializeDefaultAppClient之后的测试中有一个错误。
一定是
if (client.auth.hasDeviceId) { ... }而不是
if (client.auth.isLoggedIn) { ... }这总是错误的,因为client.auth是在测试之后生成的。
https://stackoverflow.com/questions/59211331
复制相似问题