From 8ab6a8599d49e94f3fc94bcc00cfb19db640af8d Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sun, 29 Sep 2024 21:47:45 -0400 Subject: [PATCH] Use personal auth if logged in via google. --- server/googleActions.js | 6 ++++-- server/homebrew.api.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/server/googleActions.js b/server/googleActions.js index 09e51b0bd..b042a00e6 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -147,8 +147,10 @@ const GoogleActions = { return brews; }, - updateGoogleBrew : async (brew)=>{ - const drive = googleDrive.drive({ version: 'v3', auth: defaultAuth }); + updateGoogleBrew : async (brew, auth = defaultAuth)=>{ + const drive = googleDrive.drive({ version: 'v3', auth: auth }); + + console.log(auth == defaultAuth ? 'UPDATE w SERVICEACC' : 'UPDATE w USERACC') await drive.files.update({ fileId : brew.googleId, diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 22e2cee7b..0f2283c2b 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -353,7 +353,7 @@ const api = { if(!brew.googleId) return; } else if(brew.googleId) { // If the google id exists and no other actions are being performed, update the google brew - const updated = await GoogleActions.updateGoogleBrew(api.excludeGoogleProps(brew)); + const updated = await api.updateGoogleBrew(req.account, api.excludeGoogleProps(brew), res); if(!updated) return; } @@ -397,6 +397,15 @@ const api = { res.status(200).send(saved); }, + + updateGoogleBrew : async (account, brew, res)=>{ + let oAuth2Client; + if(account.googleId) + oAuth2Client = GoogleActions.authCheck(account, res); + + return await GoogleActions.updateGoogleBrew(brew, oAuth2Client); + }, + deleteGoogleBrew : async (account, id, editId, res)=>{ const auth = await GoogleActions.authCheck(account, res); await GoogleActions.deleteGoogleBrew(auth, id, editId);