From 83b798dba0ea54f5993cba8a8577559a04852825 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 23 Jun 2021 08:31:22 +1000 Subject: [PATCH] Refresh gmail tokens prior to emailing events --- app/Jobs/Mail/NinjaMailerJob.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 7ff82de2d6ab..4564aaffe348 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -178,7 +178,14 @@ class NinjaMailerJob implements ShouldQueue $google = (new Google())->init(); try{ + + if ($google->getClient()->isAccessTokenExpired()) { + $google->refreshToken($user); + $user = $user->fresh(); + } + $google->getClient()->setAccessToken(json_encode($user->oauth_user_token)); + } catch(\Exception $e) { $this->logMailError('Gmail Token Invalid', $this->company->clients()->first()); @@ -186,9 +193,7 @@ class NinjaMailerJob implements ShouldQueue return $this->setMailDriver(); } - if ($google->getClient()->isAccessTokenExpired()) { - $google->refreshToken($user); - } + /* * Now that our token is refreshed and valid we can boot the