From 0a5bfe293921607192a2856d4fcc7b4aefca1f61 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Thu, 1 Dec 2022 19:51:36 -0600 Subject: [PATCH] check if `keys` exist before trying for auth. --- server/googleActions.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/googleActions.js b/server/googleActions.js index 56f449cfd..b29110d8d 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -5,23 +5,25 @@ const { nanoid } = require('nanoid'); const token = require('./token.js'); const config = require('./config.js'); -const keys = typeof(config.get('service_account')) == 'string' ? - JSON.parse(config.get('service_account')) : - config.get('service_account'); let serviceAuth; -try { - serviceAuth = google.auth.fromJSON(keys); - serviceAuth.scopes = [ - 'https://www.googleapis.com/auth/drive' - ]; -} catch (err) { - if(!keys){ - console.log('No Google Service Account in config files - Google Drive functionality will not function.'); - } else { +if(!config.get('service_account')){ + console.log('No Google Service Account in config files - Google Drive functionality will not function.'); +} else { + const keys = typeof(config.get('service_account')) == 'string' ? + JSON.parse(config.get('service_account')) : + config.get('service_account'); + + try { + serviceAuth = google.auth.fromJSON(keys); + serviceAuth.scopes = [ + 'https://www.googleapis.com/auth/drive' + ]; + } catch (err) { console.warn(err); console.log('Please make sure that a Google Service Account is set up properly in your config files.'); } } + google.options({ auth: serviceAuth || config.get('google_api_key') }); const GoogleActions = {