How use Google Calendar API to insert an event in end-user's calendar with Next.js

Hello,
I'm trying to setup a call to Google Calendar API to insert an event in end-user with Next.js but I'm drowning in the documentation.
I'm stuck on the authentication of the end-user. Here what I've done till now :
  • I created a OAuth 2.0 ID Client from Google Cloud Console
  • Imported the .json file in my Next.js application
  • I used NextAuth and googleapis (Node.js google library for authentification)
  • Used the googleapis to try to authenticate the end-user and get an access-token. Here the error message I got : "key must be a string, a buffer or an object"
Here the code creating the error :
export async function authenticate() {
    const keyFilePath = path.join(process.cwd(), 'credentials.json');
    console.log(keyFilePath)
    const auth = new google.auth.GoogleAuth({
        keyFile: keyFilePath,
        scopes: ['https://www.googleapis.com/auth/calendar.events', 'https://www.googleapis.com/auth/calendar'],
    });
    return await auth.getClient();
} 

I don't understand because keyFilePath is a string.. I've tried to replace it with the content of the file directly, as an object, but then I got the error message : The "paths[0]" argument must be of type string. Received an instance of Object ..

Does anyone has experience with Google APIs, OAuth 2.0 or Next.js ? Or can direct me towards great resources ? I'm a bit lost with all the google documentation.

Thanks !
Was this page helpful?