Socket
Socket
Sign inDemoInstall

react-native-simple-google-login

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-simple-google-login

A `<GoogleLogin />` component for react-native no native code added light weight library to make user Google login. No setup, no linking required, use it like a component.


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
2.76 MB
Created
Weekly downloads
 

Readme

Source

react-native-simple-google-login

npm (tag) PRs Welcome GitHub top language David publish size

A <GoogleLogin /> component for react-native no native code added light weight library to make user Google login. No setup, no linking required,use it like a component.

This module uses Google OAuth2.

Installation

npm i --save react-native-simple-google-login

or

yarn add react-native-simple-google-login

Linking

As this module uses react-native-webview react-native-webview as dependencies, it's required to link them at the moment.

react-native link react-native-webview
react-native link @react-native-community/async-storage

TODO: Making the them automate

Setup Instructions

  1. Go to the Google Developers Console
  2. Select your project or create a new one (and then select it)
  3. Create a service account for your project
  • In the sidebar on the left, expand APIs & auth > Credentials
  • Click blue "Add credentials" button
  • Select the "OAuth client ID" option
  • Select the "other" key type option
  • Click blue "Create" button
  • Save the Client_id, that's all you need (it is the only copy!)

Props

namedesctypedefault
credentialsDetailsGoogle client detailsobject{redirectUrl: '', clientId:''}
scopescope for the login which will be included in access tokenstring'profile email openid'
getAccessTokenCallback for access token when token receivedfunctionundefined
getUserDetailsCallback for user details when receivedfunctionundefined

Usage

import React, { useState } from 'react';
import GoogleLogin, { getCurrentUser, getToken, getStatus, revokeAccess } from 'react-native-simple-google-login';

export default function App() {
  const clientId = 'YOUR_CLIENT_ID';
  const GOOGLE_REDIRECT_URI = 'http://localhost';
  const [ isLoggedIn, setLoggedIn ] = useState(false);

  function _onPressLoginButton() {
    if(isLoggedIn) {
      //do something else
    } else {
      setLoggedIn(true);
    }
  }

  function getAccessToken(token) {
      console.log(token, 'User logged in, token received');
      setLoggedIn(false);
  }

  function getUserDetails(data) {
      console.log(data, 'User details received');
  }

  function _onPressDetailsButton() {
    getCurrentUser().then(userDetails => {
      console.log(userDetails, 'stored user details in async storage');
    });
  }

  return (
    <View style={{flex: 1}}>
      <GoogleLogin
        credentialsDetails={{
          redirectUrl: GOOGLE_REDIRECT_URI,
          clientId,
        }}
        getAccessToken={getAccessToken}
        getUserDetails={getUserDetails}
      />
      <TouchableOpacity onPress={_onPressLoginButton}>
        <Text>Login with Google</Text>
      </TouchableOpacity>
      <TouchableOpacity onPress={_onPressDetailsButton}>
        <Text>Get user details</Text>
      </TouchableOpacity>
    </View>
  )
}

Docs

Exposed data: userDetails, accessToken, sessionValid

namedesctypedefault
getCurrentUserDetails of user logged inPromisenull
getTokenAccess token after logged inPromisenull
getStatusReturns a bool value which can be checked if the user is already logged inPromisenull
revokeAccessRemove your application from the user authorized applications.Promisenull

Dependency

react-native-webview react-native-webview

Contribute

Help to make it better! Please see CONTRIBUTING.md for more details.

License


MIT License

Keywords

FAQs

Last updated on 30 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc