question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot destructure property `client_secret` of 'undefined' or 'null'.

See original GitHub issue

Expected Behavior

expected the script to work.

Actual Behavior

I got an error. const {client_secret, client_id, redirect_uris} = credentials.installed; ^

TypeError: Cannot destructure property client_secret of ‘undefined’ or ‘null’. at authorize (C:\Users\Mustafa Aygün\Desktop\code\emailer_test\quickstart.js:26:65) at fs.readFile (C:\Users\Mustafa Aygün\Desktop\code\emailer_test\quickstart.js:16:3) at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

Steps to Reproduce the Problem

Specifications

  • Node version (node -v)
  • OS (Mac/Linux/Windows)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
nmahajanoiicommented, Aug 16, 2020

var clientSecret = credentials.installed.client_secret; In this line credentials is pointing to client_secret.json so the first key has to be “installed”. In my case the key was “web” and that was causing the error. I just renamed the key “web” to “installed”.

0reactions
vela91commented, Apr 20, 2022

I was having the same issue…not sure if this is the “best” solution…but it works.

• delete const {client_secret, client_id, redirect_uris} = credentials.installed;

• replace with: var client_secret = credentials.client_secret; var client_id = credentials.client_id; var redirect_uris = credentials.redirect_uris;

• resulting in the following authorize function: `function authorize(credentials, callback) { var client_secret = credentials.client_secret; var client_id = credentials.client_id; var redirect_uris = credentials.redirect_uris;

const oAuth2Client = new google.auth.OAuth2( client_id, client_secret, redirect_uris);

// Check if we have previously stored a token. fs.readFile(TOKEN_PATH, (err, token) => { if (err) return getAccessToken(oAuth2Client, callback); oAuth2Client.setCredentials(JSON.parse(token)); callback(oAuth2Client); }); }`

thanks that was the only way to fix my issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - cannot read property 'client_secret' of undefined
var clientSecret = credentials.installed.client_secret; In this line credentials is pointing to client_secret.json so the first key has to be "installed".
Read more >
Cannot destructure Property of Undefined Error in JS
The "Cannot destructure property of undefined" error occurs when we try to destructure a property from a value that is equal to `undefined`....
Read more >
Cannot Destructure Property 'Timeout' Of 'Undefined' Or 'Null'
Fixed an issue where Cloud Firestore didn't detect Authentication which led to permission This causes data to be returned which doesn't match the...
Read more >
Cannot destructure property 'client_secret' of 'credentials ...
var clientSecret = credentials.installed.client_secret; In this line credentials is pointing to client_secret.json so the first key has to ...
Read more >
Node.js quickstart | People API - Google Developers
The OAuth client created screen appears, showing your new Client ID and Client secret. Click OK. ... @return {Promise<OAuth2Client|null>}
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found