From f7cb0dcebb0514cf38f8a7e635ec9959c196145a Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 4 Jun 2025 21:32:34 -0400 Subject: cleaned up getting client id/secret for google. fixed final message after going through authentication process. --- src/server/ApiManagers/GeneralGoogleManager.ts | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/server/ApiManagers') diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts index 59d066934..693b17779 100644 --- a/src/server/ApiManagers/GeneralGoogleManager.ts +++ b/src/server/ApiManagers/GeneralGoogleManager.ts @@ -96,25 +96,26 @@ export default class GeneralGoogleManager extends ApiManager { register({ method: Method.GET, subscription: '/refreshGoogle', - secureHandler: async ({ user, req, res }) => { - const code = req.query.code as string; - - try { - const enriched = await GoogleApiServerUtils.processNewUser(user.id, code); - - if (enriched.refresh_token) { - if (enriched.refresh_token) { - user.googleToken = enriched.refresh_token; - await user.save(); - } else { - console.warn('No refresh token returned'); - } - } - } catch (err) { - console.error('Failed to process Google code:', err); - res.status(500).send('Error linking Google account'); - } - }, + secureHandler: async ({ user, req, res }) => + new Promise(resolve => + GoogleApiServerUtils.processNewUser(user.id, req.query.code as string) + .then(enriched => { + if (enriched.refresh_token) { + if (enriched.refresh_token) { + user.googleToken = enriched.refresh_token; + user.save(); + } else { + console.warn('No refresh token returned'); + } + } + res.status(200).send('Google account linked successfully!'); + }) + .catch(err => { + console.error('Failed to process Google code:', err); + res.status(500).send('Error linking Google account'); + }) + .finally(resolve) + ), }); } } -- cgit v1.2.3-70-g09d2