我正在使用原生代码的react native。使用‘react-native-native feed’库,我正在尝试让Stream feed在我的应用程序上启动并运行。
我已经使用api密钥、应用程序Id和应用程序密钥设置了我的流帐户。使用firebase函数,我在创建帐户时为用户创建令牌服务器端,然后将其保存到数据库。
const client = stream.connect(
functions.config().stream.key_id,
functions.config().stream.secret,
);
const userToken = client.createUserToken(user.uid);
admin.database().ref('users/' + user.uid ).set({
token: userToken
})在客户端,我检索当前用户的令牌,然后将其(以及应用程序Id和应用程序密钥)传递给对象。我希望得到一个没有错误的空feed,但是我得到了来自Stream的“数据未定义”错误。
为了开始使用StreamApp对象,我还需要创建客户端或服务器端吗?
import {StreamApp} from 'react-native-activity-feed
render() {
const { currentUser } = this.state
const {streamToken} = this.state
let apiKey = Config.STREAM_API_KEY;
let appId = Config.STREAM_APP_ID;
userId = firebase.auth().currentUser.uid;
let token;
tokenRef = firebase.database().ref(`users/${userId}`);
tokenRef.on('value', (snapshot) => {
token = snapshot.val().token;
})
return (
<StreamApp
apiKey={apiKey}
appId={appId}
token={token}
>
</StreamApp>
)
}
}错误:
TypeError:未定义不是对象(计算“”client.currentUser.data“”)
此错误位于:
在StreamApp( ... )中...
发布于 2019-08-03 02:27:41
最终,在服务器返回流令牌之前,render函数被调用是一个问题。
为了解决这个问题,我给了页面从服务器加载流令牌的时间:
render() {
if(this.state.loading) {
return (<View style={[styles.container, styles.horizontal]}><ActivityIndicator size="large" color="#0000ff" /></View>);
}
return (
<StreamApp
apiKey={this.state.apiKey}
appId={this.state.apiId}
token={this.state.streamToken}
>
</StreamApp>
)
}
}https://stackoverflow.com/questions/57078265
复制相似问题