在博览会上登录Google Auth无法正常工作

时间:2019-07-03 16:46:25

标签: react-native expo google-authentication

当我按下使用google按钮登录时,它什么也没做

我关注了https://docs.expo.io/versions/latest/sdk/google/

iosClientId:'my-id',通常是我的Google clientid,但出于安全原因将其更改

import React, { Component } from 'react';
import {StyleSheet, Text, View, Button} from 'react-native';

class LoginScreen extends Component {
    async signInWithGoogleAsync () {
        try {
            const result = await Expo.Google.logInAsync({
                //androidClientId: YOUR_CLIENT_ID_HERE,
                behavior: 'web',
                iosClientId: 'my-id',
                scopes: ['profile', 'email'],
            });

            if (result.type === 'success') {
                return result.accessToken;
            } else {
                return { cancelled: true };
            }
        } catch (e) {
            return { error: true };
        }
    }
    render() {
        return (
            <View style={styles.container}>
                <Button title={"Sign In With Google"}
                 onpress={() =>this.signInWithGoogleAsync()}
                />
            </View>
        );
    }
}
export default LoginScreen;

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF'
    }
});

我希望是当我按下“使用Google登录”按钮时让我登录

但是我得到的是按钮什么都不做

1 个答案:

答案 0 :(得分:0)

将渲染功能更改为此:

render() {
    return (
        <View style={styles.container}>
            <Button title={"Sign In With Google"}
             onPress={() =>this.signInWithGoogleAsync()}
            />
        </View>
    );
}