0.2.1 • Published 12 months ago

react-native-google-signin-latest v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-native-google-signin-latest

Google signin Using latest implementation (Credential Manager). NOTE: It's still Android** only package. Any contribution will be welcomed :)

Installation

npm install react-native-google-signin-latest

If you are using Yarn:

yarn add react-native-google-signin-latest

Usage

import { GoogleSignin } from 'react-native-google-signin-latest';
import { WEB_CLIENT_ID } from '@env';
// ...

useEffect(() => {
  // WEB_CLIENT_ID ==> Add this value to your .env in the example folder
  GoogleSignin.configure({ webClientId: WEB_CLIENT_ID })
}, []);

const handleSignIn = async () => {
  await GoogleSignin.signIn().then((res) => {
    console.log('GoogleSignin.signIn_res ', res);
  }).catch((err) => {
    console.error('GoogleSignin.signIn_err ', err);
  })
}

const handleSignInWithGoogleButton = async () => {
  await GoogleSignin.signInWithGoogleButton().then((res) => {
    console.log('GoogleSignin.signInWithGoogleButton_res ', res);
  }).catch((err) => {
    console.error('GoogleSignin.signInWithGoogleButton_err ', err);
  })
}

const handleSignOut = async () => {
  await GoogleSignin.signOut().then((res) => {
    console.log('GoogleSignin.signOut_res ', res);
  }).catch((err) => {
    console.error('GoogleSignin.signOut_err ', err);
  })
}

return (
  <View style={styles.container}>
    <TouchableOpacity style={{marginTop: 50, backgroundColor: 'white', borderRadius: 100, padding: 20}} onPress={handleSignIn}>
      <Text style={{color: '#000', fontWeight: 800}}>Google Sign In</Text>
    </TouchableOpacity>
    <TouchableOpacity style={{marginTop: 50, backgroundColor: 'white', borderRadius: 100, padding: 20}} onPress={handleSignInWithGoogleButton}>
      <Text style={{color: '#000', fontWeight: 800}}>Google Sign In With Google Button</Text>
    </TouchableOpacity>
    <TouchableOpacity style={{marginTop: 50, backgroundColor: 'white', borderRadius: 100, padding: 20}} onPress={handleSignOut}>
      <Text style={{color: '#000', fontWeight: 800}}>Google Sign Out</Text>
    </TouchableOpacity>
  </View>
);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library