npm.io
0.2.0 • Published 5 years ago

@ganesshkumar/gapi

Licence
Apache-2.0
Version
0.2.0
Deps
0
Size
42 kB
Vulns
0
Weekly
0

gapi

A thin Node wrapper for Google's client-side javascript V3 API with TypeScript declaration.

Example

npm install --save gapi-client

yarn add gapi-client

index.js:

import gapi from '@ganesshkumar/gapi';

gapi.load('client:auth2', () => {
  gapi.client.init({
    discoveryDocs: ["<discoveryDocs_corresponding_to_the_APIs_you_use>"],
    clientId: '<your_client_id>',
    scope: '<scope_you_want_to_add>'
  }).then(function () {
    // do stuff with loaded APIs
    gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
    updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
  });
});

const updateSigninStatus = (isSignedIn) => {
  if (isSignedIn) {
    console.log('User is signed in')
  } else {
    console.log('User is not signed in')
  }
}

// To trigger the sign in flow, you can call the following function from appropriate place.
gapi.auth2.getAuthInstance().signIn();

TypeScript

This repo has the basic support for TypeScript.

License

Apache-2.0