Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React native - prevent user from going back to login screen

$
0
0

I've created a Login button using Facebook SDK. Once the user is logged in, the app navigates to the second screen (NavigatorIOS). From that second screen the user can go back to the login screen using the navigation (back button).

How can I prevent the user from going back to the Login screen if he is already logged in?

index.ios.js

import React, { Component } from 'react'import {  AppRegistry,  StyleSheet,  NavigatorIOS} from 'react-native'import LoginView from './src/login-view'class MyApp extends Component {  render() {    return (<Provider store={store}><NavigatorIOS          initialRoute={{            component: LoginView,            title: 'MyApp',            index: 0          }}        /></Provider>    );  }}AppRegistry.registerComponent('MyApp', () => MyApp);

LoginView

import React, {Component} from 'react'import {    View,    Text,    StyleSheet,    TouchableHighlight,} from 'react-native'import CategoryView from './category-view'import {LoginButton, AccessToken, GraphRequest, GraphRequestManager} from 'react-native-fbsdk'class LoginView extends Component {    goToCategoryView = () =>        this.props.navigator.push({            title: 'Categories',            component: CategoryView,        })    render(){        return(<View style={styles.container}><LoginButton                    readPermissions={['public_profile','email']}                    onLoginFinished={                        (error, result) => {                            if (error) {                                console.log('login has error: ', result.error)                            } else if (result.isCancelled) {                                console.log('login is cancelled.')                            } else {                                AccessToken.getCurrentAccessToken().then((data) => {                                        this.goToCategoryView()                                })                            }                        }                    }                    onLogoutFinished={() => {console.log('logged out')}} /></View>        )    }}export default LoginView

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>