3

I have a React + Electron app using Google API to authenticate and get a list of calendar events.

The API script is being loaded on the head of my index.html and initialised on my App.js like so:

// Initializes the API client library and sets up sign-in state listeners.
  initClient() {
    let gapi = window["gapi"];
    let that = this;

    gapi.load("client", start);

    function start() {
      gapi.client
        .init({
          apiKey: GOOGLE_API_KEY,
          clientId: CLIENT_ID,
          discoveryDocs: [
            "https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"
          ],
          scope: "https://www.googleapis.com/auth/calendar.readonly"
        })
        .then(() => {
          gapi.auth2
            .getAuthInstance()
            .isSignedIn.listen(that.updateSigninStatus);

          that.updateSigninStatus(
            gapi.auth2.getAuthInstance().isSignedIn.get()
          );

          that.setState({
            apiLoaded: true
          });
        });
    }
  }

It works completely fine on a local environment, where I have a server running, but once I build my Electron app and run the app "natively", I get the following error: gapi.auth2.ExternallyVisibleError: Invalid cookiePolicy

I don't have an advanced understanding of APIs and Servers to figure this out but through research, I found something about the API not working from a "file://" protocol, which is the case on an Electron app.

Thoughts? Ideas?

Matt Costa
  • 233
  • 1
  • 10

0 Answers0