Tips for getting a plugin to function properly when the page is refreshed in Nuxt app

I am currently incorporating the vue GAPI plugin into my project.

While it functions smoothly when navigating between pages, I encounter an error upon refreshing:

vue-gapi.common.js?15fd:241 Uncaught (in promise) Error: gapi not initialized at GoogleAuthService.isSignedIn (vue-gapi.common.js?15fd:241)

I suspect that the issue lies in how I am initializing the component within my project - specifically through the /plugins folder. It seems like I may be attempting to use GAPI before it has fully loaded, and even when trying to wrap a call to GAPI in a promise, it immediately rejects with the aforementioned error. What would be the correct approach to address this? Below is the code for my gapi plugin:

import Vue from "vue";
import VueGAPI from "vue-gapi";
const apiConfig = {
  apiKey: "xxx",
  clientId:
    "xxx.apps.googleusercontent.com",
  discoveryDocs: [
    "https://content.googleapis.com/discovery/v1/apis/drive/v3/rest",
    "https://content.googleapis.com/discovery/v1/apis/slides/v1/rest"
  ],
  scope:
    "https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/presentations.readonly",
  refreshToken: true
};
Vue.use(VueGAPI, apiConfig);

nuxt.config.js contains the following:

  plugins: [
    { src: "~plugins/gapi.js", ssr: false },
  ],

Any suggestions on how to resolve this issue are greatly appreciated.

Thank you

Answer №1

My solution involved using a promise to wrap the call to this.$isSignedIn(). By making multiple attempts to resolve this.$isSignedIn(), I was able to set a data prop on my component upon success. This data prop acted as the trigger for subsequent actions to occur, marking the sign-in process as 'complete'.

Exploring other methods proved futile without alterations to the NPM package.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending files using AJAX without FormData in Internet Explorer 9

Unfortunately, IE9 does not support FormData, making file uploads via XMLHttpRequest a more challenging task. Is there a workaround for this issue? I've come across mentions of using iFrames, but the process seems complex and unclear on how to transf ...

Check the input in the text box against the selected options to validate it

Currently, I am working on an add contacts page where I am facing the challenge of displaying an error message or highlighting input as invalid if a user tries to enter a contact name that already exists. It seems like one solution could be populating a s ...

What is the best way to send the entire image to an API route in Next.js so that I can save it using FS and then upload it to Cloudinary?

I have a form here that utilizes React Hook Form. I'm wondering what I need to pass to the API endpoint via fetch in order to write an image to disk using fs, retrieve its location, and then send that location to Cloudinary. In the body of the fetch ...

Ordering dates by week in AngularJS 1

Currently, I have a list of objects: [{ name: one, date: 2017-09-18 }, { name: two, date: 2017-09-11 }, { name: three, date: 2017-09-13 }] I am looking to organize this list by week. Perhaps like the following structure: { 1week(or , m ...

Utilizing vue-router for passing concealed information

My goal is to transfer data between routes without displaying it in the URL, unlike with route parameters. The information I need to pass is an authentication key that is lengthy and should remain concealed from the user. Can this be accomplished using ro ...

The TypeScript inference feature is not functioning correctly

Consider the following definitions- I am confused why TypeScript fails to infer the types correctly. If you have a solution, please share! Important Notes: * Ensure that the "Strict Null Check" option is enabled. * The code includes c ...

Ways to retrieve and bind data using onMounted in VueJS

Loading Data in Test.vue Component <template> <li v-for="item in masterCompany" v-bind:key="item.id"> {{ item.displayName }} </li> </template> <script> import Test from "../hooks/Test.hook" ...

Is there a way to directly access the React component that was clicked?

I'm looking to dynamically change the class of a component when clicked. By using state to create a new component with properties such as name and done (initiated as false), which are then added to the todos array, I want to find out how to identify t ...

The Bootstrap tooltip effectively fades away after displaying text, but it is not positioned correctly above the icon

Having some issues with my tooltip functionality. It seems to display the text on the left side and fades away upon mouseover, but it doesn't show up in a proper tooltip box over the icon as expected. I suspect that there might be a conflict between j ...

Exploring the process of logging large objects in Node.js 11 using the console command

When working with Node.js 11, I've noticed that when I use console.log to output a large object, it sometimes throws a stack trace error or logs the full object including all of its inheritance. In my Jest tests, I encountered an error when trying to ...

Tips for using JavaScript to set images from Flickr API as img src

I've been attempting to populate a table with images fetched from flickr. The array I'm using consists of urls like: ["https://www.flickr.com/photos/113081696@N07/24695273486", "https://www.flickr.com/photos/113081696@N07/24565358002", "https:// ...

Issues with the initial calculator project I built using JavaScript (excluding HTML and CSS)

My first calculator is nearly complete, but I have encountered a challenge. The functionality of my calculator is quite simple; it prompts the user for input using window.prompt and performs addition, subtraction, multiplication, or division based on the u ...

What is the feature of a Vue.js component that removes other sibling markup?

While diving into the world of Vue, I encountered an interesting behavior that has left me wondering. I have my main markup set up and realized that a part of it could work as a separate component. However, when I tried adding this component to the contain ...

Simple JavaScript timer with loop and pause

Having trouble with a countdown script and encountering multiple issues. The script does not run smoothly Difficult to make it repeat (closure) Struggling with delaying the start and repeat (closure) Seeking assistance in fixing this code which should i ...

What is the process for importing a JSON5 file in Typescript, just like you would with a regular JSON file?

I am looking to import a JSON5 file into a JavaScript object similar to how one can import a JSON file using [import config from '../config.json']. When hovering over, this message is displayed but it's clearly visible. Cannot find module & ...

A guide to effectively converting and parsing a class object that includes Uint8Array elements

After stringifying a class object that contains a property in Uint8Array, and then parsing it later, the property is no longer in Uint8Array format. Here's an example: class Example { title:string; byteData:Uint8Array; ...

How come JSON.parse is altering the data within nested arrays?

In my journey to master Angular 2, I decided to challenge myself by creating a Connect Four game using Angular CLI back when it was still utilizing SystemJS. Now, with the switch to the new Webpack-based CLI, I am encountering a peculiar issue... The fun ...

Add a variety of parameters to the URL in order to make an AJAX request

I want to dynamically add values from checked checkboxes to a URL for use in an AJAX call. I only want these values to be added to the URL if the checkbox is checked. If a user checks and then unchecks, I do not want that value included in the URL. Below ...

Employ a class function within router.get

I'm a beginner with node.js and I'm running into an issue when trying to use a class method in the router.get callback function. Can someone assist me with this problem? Route.get() is expecting a callback function but received a [object object] ...

Is there a method to ascertain the relative position of a point on a polygon?

Apologies in advance as I might have a hard time wording this question properly, so I'll start by explaining my objective. I'm currently working with JavaScript and Raphael. My goal is to save the position of a point in relation to the four cor ...