如何解决useParseQuery 和 back4app 出现 401 错误
我尝试使用带有 Parse 服务器的 back4end 作为我的 React Native 应用程序的后端,但无法进行查询。
我在 App.js 中初始化 Parse :
import React,{ useState,useEffect } from 'react';
import { Platform } from 'react-native'
import * as eva from '@eva-design/eva';
import { ApplicationProvider,IconRegistry } from '@ui-kitten/components';
import { EvaIconsPack } from '@ui-kitten/eva-icons';
import { AppNavigator,AuthNavigator } from './navigation';
import keys from './config/back4app';
import { initializeParse } from '@parse/react-native';
import UserContext from './config/context';
initializeParse(keys.serverURL,keys.applicationId,keys.javascriptKey);
export default () => {
const [user,setUser] = useState(null);
const [isLoading,setIsLoading] = useState(true);
useEffect(() => {
async function getCurrentUser() {
if (user === null) {
const currentUser = await Parse.User.currentAsync();
if (currentUser !== null) {
setUser(currentUser);
}
}
}
getCurrentUser();
setIsLoading(false);
},[user]);
if (isLoading) {
return null; // spinner
}
return(
<UserContext.Provider value={user}>
<IconRegistry icons={EvaIconsPack}/>
<ApplicationProvider {...eva} theme={eva.light}>
{ user ? <AppNavigator/> : <AuthNavigator/> }
</ApplicationProvider>
</UserContext.Provider>
);
};
import React,{ useContext } from 'react';
import { StyleSheet,ActivityIndicator } from 'react-native';
import { Button,List,Text } from '@ui-kitten/components';
import { Page } from '../components/page';
import { Post } from '../components/post';
import { useParseQuery } from '@parse/react-native';
import UserContext from '../config/context';
export const FeedScreen = ({ navigation }) => {
const user = useContext(UserContext);
const parseQuery = new Parse.Query('Post');
const {
isLive,// Indicates that Parse Live Query is connected
isLoading,// Indicates that the initial load is being processed
isSyncing,// Indicates that the library is getting the latest data from Parse Server
results,// Stores the current results
count,// Stores the current results count
error,// Stores any error
reload // Function that can be used to reload the data
} = useParseQuery(parseQuery);
if (isLoading) {
return <ActivityIndicator/>;
}
return (
<Page navigation={navigation} title="Neurchi">
<Text>welcome {user.get('username')}</Text>
{error && (
<Text>{error}</Text>
)}
<List
style={styles.container}
contentContainerStyle={styles.contentContainer}
data={results}
renderItem={(info) => <Post item={info.item}/>}
/>
</Page>
);
};
const styles = StyleSheet.create({
container: {
},contentContainer: {
paddingHorizontal: 8,paddingVertical: 4,},item: {
marginVertical: 4,});
我收到此错误:
WebSocket connection to 'wss://parseapi.back4app.com/' Failed: Unexpected response code: 401
我尝试在另一个屏幕中再次初始化 Parse,但没有进行任何更改。此外,当我在 App.js 中发出请求时,它会起作用!所以我猜是授权问题...
希望有人有想法,提前谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。