如何做登出反应原生



如何在我的项目中进行签出?另外,大多数方法都不工作,因为我把我的数据通过REST API到firebase,请帮助我。这是Profile.js,我需要实现logOut函数

const Profile = () => {
const [user] = useAuth()
const navigation = useNavigation()
const logOut = () => {
This function
};

return (
<View style={styles.container}>
<View style={styles.header}>
<Image
source={require('../assets/images/Logo_small.png')}
style={styles.logo_s}
resizeMode='contain'/>
</View>
<View style={styles.main_cont}>
<Profile_text marginBottom={28}/>
<View style={styles.replace}>
<TextInput
style={styles.inp}
placeholder={user.displayName}
placeholderTextColor= 'rgba(207, 77, 79, 0.75)'
editable={false}/>
<Pressable onPress={''}>
<Image
source={require('../assets/images/replace_btn.png')}
style={styles.replace_btn}
resizeMode='contain'/>
</Pressable>
</View>
<UnderLine marginBottom={500}/>
<Pressable style={styles.result} onPress={logOut}>
<Text style={styles.text_result}>Выйти из профиля</Text>
</Pressable>
</View>
<Image
source={require('../assets/images/bottom_menu.png')}
style={styles.img_bg}/>
</View>
)
}

There is App.js

const Stack = createNativeStackNavigator();
const Navigator = () => {
const [user] = useAuth()
if(!user) {
return (
<Stack.Navigator
screenOptions={{
headerShown: false
}}>
<Stack.Screen  name="Login" component={LoginScreen} />
<Stack.Screen name="Registration" component={RegistrationScreen} />
</Stack.Navigator>
)
}
return (   
<NavigationBar/>
)
}

我也有一个导航栏:

<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarStyle: {
height: 80,
position:'absolute',
backgroundColor: 'transparent',
elevation: 0,
},
tabBarLabelStyle: {color: '#000000'}
}}
tabBarOptions={{
showLabel: false,
}}>
<Tab.Screen name="Profile" component={Profile} options={{
tabBarIcon: ({focused}) => (
<View>
<Image
source={focused ? require('../assets/images/profile_use.png') : require('../assets/images/profile.png') }
style={{
width: 50,
height: 50,
}}
resizeMode='contain'/>
</View>
),
}}/>
<Tab.Screen name="Train" component={Train} options={{
tabBarIcon: ({focused}) => (
<View>
<Image
source={focused ? require('../assets/images/train_use.png') : require('../assets/images/train.png') }
style={{
width: 50,
height: 50,
}}
resizeMode='contain'/>
</View>
),
}}/>
<Tab.Screen name="Statistics" component={Statistics} options={{
tabBarIcon: ({focused}) => (
<View>
<Image
source={focused ? require('../assets/images/statistic_use.png') : require('../assets/images/statistic.png') }
style={{
width: 50,
height: 50,
}}
resizeMode='contain'/>
</View>
),
}}/>
</Tab.Navigator>  

请帮帮我,我只是react native的初学者。再次:什么需要注销?可能我不能这样做,因为我的授权是在堆栈导航器,但配置文件是在Tab导航器,请帮助

Try

const [user, setUser] = useAuth()  
logout = () => {
setUser(false)
}

最新更新