世博会在 Facebook 登录后不重定向用户

时间:2020-12-30 15:24:44

标签: javascript reactjs react-native facebook expo

使用 expo facebook 登录时,我正在弹出窗口并能够点击 continue as ... 但在点击它并收到成功警报消息后,用户没有被重定向到主屏幕...

我尝试在其下方添加导航,以便希望将用户导航到下一个屏幕,但仍然失败。我可能一直在做 javascript 错误,但我不知道为什么它不起作用。

export default class LoginScreen extends Component {


    navigateToScreen = (route, params = {}) => () => {
        const navigateAction = NavigationActions.navigate({
            routeName: route,
            params
        });
        this.props.navigation.dispatch(navigateAction);
    }


    // facebook login
    FBlogIn = async () => {
        try {
            await Facebook.initializeAsync({
                appId: '[my app id is here]',
            });
            const {
                type,
                token,
                expires,
                permissions,
                declinedPermissions
            } = await Facebook.logInWithReadPermissionsAsync({
                permissions: ["public_profile"]
            });

            if (type === "success") {
                // Get the user's name using Facebook's Graph API
                const response = await fetch(
                    `https://graph.facebook.com/me?access_token=${token}`
                );
    // this gives the alert of logged in ... I have even tried commenting this out so it 
    // would just go to Home Screen but still failed
                Alert.alert("Logged in!", `Hi ${(await response.json()).name}!`);
    // this to make this a function and then pass it here but that failed as well
                            this.navigateToScreen('Home')

                this.props.navigation.dispatch(navigateAction);
            } else {
                alert(`Facebook Login Error: Cancelled`);
            }
        } catch ({ message }) {
            alert(`Facebook Login Error: ${message}`);
        }
    };
    
render()
return (
                        {/* for facebook signin */}
    <Button rounded block onPress={this.FBlogIn} style={styles.button_start} activeOpacity={1}>
            <Text style={{ color: '#222222', fontWeight: 'bold', fontSize: 14 }}>Login with Facebook</Text>
    </Button>
    )

0 个答案:

没有答案