google signIn with react native firebase

 1: first of all create project in firebase console

2:choose Android

3:add android pakage name from

android/app/src/main /android manifest.xml0

4:copy pakage name and paste into firebase 

5:then skip other and click on register app

6:then click next

7:then copy classpath 'com.google.gms:google-services:4.3.10'

and paste into android/build.gradle in  dependencies

8:then copy apply plugin: 'com.google.gms.google-services' and paste into app/build.gradle in last 

9:then copy this dependenci implementation platform('com.google.firebase:firebase-bom:29.1.0')

and paste into app/build.gradle dependencies

10:then click next button then click continue to console

11:then go to firebase project settings

12:then Add SHA  key fingerprints just run this command cd android then run this command ./gradlew signingReport  into terminal to generate SHA  key  and copy it then paste it into firebase  certificate fingerprint

then copy SHA256 key and past it into firebase  certificate fingerprint SHA 256

13:then download google-servies.json file from firebase and past it into Android/App folder

14:then install RNfirebase pakage for react native

npm install --save @react-native-firebase/app
15:then install RNfirebase auth module 
npm add @react-native-firebase/auth
16:then install  npm install @react-native-google-signin/google-signin
17: then import google signin  and configure it like this one
import { GoogleSignin } from '@react-native-google-signin/google-signin';

GoogleSignin.configure({
  webClientId: '',
});
17: then Enable google signin from firebase project goto  authentication tab and click on get started
18:then goto google and Enable it and add (Project support email) and save it
19:then open (Web SDK configuration) from firebase google tab and copy Web client ID then paste it to WebclientId:" " 
20:import import auth and google signIn from rn firebase and google signin pkg
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import auth from '@react-native-firebase/auth';

then create the function like this 
   const signingoogle = async () => {
    try {
      await GoogleSignin.hasPlayServices();
      const userInfo = await GoogleSignin.signIn();
      console.log("userINFO",userInfo)
    } catch (error) {
      console.log("error",error)
      if (error.code === statusCodes.SIGN_IN_CANCELLED) {
        // user cancelled the login flow
      } else if (error.code === statusCodes.IN_PROGRESS) {
        // operation (e.g. sign in) is in progress already
      } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
        // play services not available or outdated
      } else {
        // some other error happened
      }
    }
  };
 

but this function only give the info only app  console not in firebase console 

21:run this function for get info into both place app console and firebase console 
  const signingoogle = async () => {
   // Get the users ID token
   const { idToken } = await GoogleSignin.signIn();

   // Create a Google credential with the token
   const googleCredential = await auth.GoogleAuthProvider.credential(idToken);
 
   // Sign-in the user with the credential
   const res = await auth().signInWithCredential(googleCredential);
   console.log("resss>>>>",res)
  };

22:if we want to get accessToken then run this function 
  const getaccestoken = async () => {

    const accesToken =  await (await GoogleSignin.getTokens()).accessToken
    console.log("To get acces token",accesToken)
   };

there are more methods are available like IsSignIn method Signout Method and much more
23:we can use google button for signIn like this

import { GoogleSignin, GoogleSigninButton } from '@react-native-google-signin/google-signin';

<GoogleSigninButton
  style={{ width: 192, height: 48 }}
  size={GoogleSigninButton.Size.Wide}
  color={GoogleSigninButton.Color.Dark}
  onPress={this._signIn}
  disabled={this.state.isSigninInProgress}
/>;
24:we can use signOut methods like this
  const signOut = async () => {
    try {
      await GoogleSignin.signOut().then(()=>{
        alert("successfully singout")
      })
      // alert('successfully signOut');
      // this.setState({ user: null }); // Remember to remove the user from your app's state as well
    } catch (error) {
      console.error(error);
    }
  };
  // getaccestoken();
  useEffect(() => {
    getaccestoken()
  }, []);

















Comments

Popular posts from this blog

NFC Checker App Privacy Policy

Privacy Policy For Real Love Calculator-Prank app

Privacy Policy for Live Weather Forecast - Realtime app