Socket
Socket
Sign inDemoInstall

native-google-login

Package Overview
Dependencies
965
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    native-google-login

google login native modules for react native


Version published
Weekly downloads
4
Maintainers
1
Created
Weekly downloads
 

Readme

Source

native-google-login

installation

1. iOS

$ yarn add native-google-login
$ cd ios
$ pod install

create GoogleLoginUtil.swift

import GoogleSignIn

@objc
class GoogleLoginUtil: NSObject {
  @objc
  static func initGoogleSDK() -> Void {
    GIDSignIn.sharedInstance()?.clientID = "YOUR_CLIENT_ID"
  }

  @objc
  static func handleOpenUrl(url: URL) -> Bool {
    guard let googleSharedInstance = GIDSignIn.sharedInstance() else {
      return false
    }
    if (googleSharedInstance.handle(url)) {
      return googleSharedInstance.handle(url)
    }
    return false
  }
}

AppDelegate.m

#import "{APPNAME}-Swift.h"
...
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  ....

  [GoogleLoginUtil initGoogleSDK];
  return YES;
}
...

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  return [GoogleLoginUtil handleOpenUrlWithUrl:url];
}

go to xcode -> info -> URL Types

add com.googleusercontent.apps.{YOUR_GOOGLE_CLIENT_ID} in url scheme

2. android

open strings.xml

<!-- add this line -->
<string name="server_client_id">YOUR_GOOGLE_CLIENT_ID</string>

open build.gradle(app)

<!-- add this line -->
implementation 'com.google.android.gms:play-services-auth:18.1.0'

how to use

import GoogleLogin from "native-google-login";

const google = async () => {
    const configure = GoogleLogin.configure({ webClientId: "WEB_OAUTH_CLIENT_ID" }) // in android, you need to provide webClientId to get idToken
    const signInResult = await GoogleLogin.googleSignIn()
    const signOutResult = await GoogleLogin.googleSignOut()
    const disconnectResult = await GoogleLogin.googleDisconnect()
}

Keywords

FAQs

Last updated on 02 Oct 2020

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