aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/GeneralGoogleManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/GeneralGoogleManager.ts')
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts39
1 files changed, 20 insertions, 19 deletions
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<void>(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)
+ ),
});
}
}