Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

react-native google sign in doesn't sign in

import React, { useEffect, useState } from 'react';
import {
    GoogleSignin,
    GoogleSigninButton,
    statusCodes,
} from '@react-native-community/google-signin';
import { Text } from 'react-native';

function GoogleSignIn() {
    const [userInfo, setUserInfo] = useState([])
    const [load, setLoad] = useState(false)
    const signIn = async () => {
        try {
            await GoogleSignin.hasPlayServices();
            const userInfo = await GoogleSignin.signIn();
            setUserInfo(userInfo);
            setLoad(!load)
            console.log(userInfo)
        } catch (error) {
            if (error.code === statusCodes.SIGN_IN_CANCELLED) {
                console.log('user cancelled the login flow')
            } else if (error.code === statusCodes.IN_PROGRESS) {
                console.log('// operation (e.g. sign in) is in progress already')
            } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
                console.log(' // play services not available or outdated')
            } else {
                console.log('something maybe wrong with SHA1 key')
            }
        }
    };
    const signOut = async () => {
        try {
            await GoogleSignin.revokeAccess();
            await GoogleSignin.signOut();
            setUserInfo(userInfo = Null); // Remember to remove the user from your app's state as well
            setLoad(false)
        } catch (error) {
            console.error(error);
        }
    };
    useEffect(() => {
        GoogleSignin.configure({
            webClientId: '476307937622-13qdp25mgqe7t4n3uqbfrqsmgs6us3n4.apps.googleusercontent.com', // client ID of type WEB for your server (needed to verify user ID and offline access)
            offlineAccess: true, // if you want to access Google API on behalf of the user FROM YOUR SERVE
        });
    })
    return (
        <>
            <GoogleSigninButton
                style={{ width: 192, height: 48 }}
                size={GoogleSigninButton.Size.Wide}
                color={GoogleSigninButton.Color.Dark}
                onPress={signIn}
            />
            {load ? <Text> success
            </Text>: <Text> failed</Text>}
        </>
    );
}
export default GoogleSignIn

here is google sign in component, i just cant figure out whats wrong with that code,it doesnt sign in so i check my debugger and it prints out this "something maybe wrong with SHA1" as i set it the way, which SHA1 to use after running ./gradlew signingReport i got three Task :app:signingReport , Task :react-native-community_google-signin:signingReport ,Task :react-native-firebase_admob:signingReport and Task :react-native-firebase_auth:signingReport and according to google we have to use

    > Task :app:signingReport
Variant: debug
Config: debug
Store: ~/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A5:88:41:04:8D:06:71:6D:FE:33:76:87:AC:AD:19:23
SHA1: A7:89:E5:05:C8:17:A1:22:EA:90:6E:A6:EA:A3:D4:8B:3A:30:AB:18
SHA-256: 05:A2:2C:35:EE:F2:51:23:72:4D:72:67:A5:6C:8C:58:22:2A:00:D6:DB:F6:45:D5:C1:82:D2:80:A4:69:A8:FE
Valid until: Wednesday, August 10, 2044

variant but i couldn't find any variant like this in Task :react-native-community_google-signin:signingReport , it only contains these two variant

> Task :react-native-community_google-signin:signingReport
Variant: releaseUnitTest
Config: none
----------
Variant: debugUnitTest
Config: debug
Store: /home/placeholer/.android/debug.keystore
Alias: AndroidDebugKey
MD5: some value
SHA1: some value
SHA-256: some value
Valid until: Sunday, January 1, 2051
----------

Variant: debugAndroidTest
Config: debug
Store: /home/placeholder/.android/debug.keystore
Alias: AndroidDebugKey
MD5: some value
SHA1: some value
SHA-256:some value
Valid until: Sunday, January 1, 2051
----------

which SHA1 key to use? is there any other issue?

question from:https://stackoverflow.com/questions/66047140/react-native-google-sign-in-doesnt-sign-in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...