From cd2ec55d82c5e66829453ef7bfd1469c18a656a1 Mon Sep 17 00:00:00 2001 From: Kenneth Obsequio Date: Tue, 14 Jul 2026 13:58:14 +0800 Subject: [PATCH] bump: email service Signed-off-by: Kenneth Obsequio --- services/email.service.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/services/email.service.js b/services/email.service.js index af651d6..6b2dce5 100644 --- a/services/email.service.js +++ b/services/email.service.js @@ -26,8 +26,7 @@ const axios = require('axios'); const { OAuth2Client } = require('google-auth-library'); const { emailTemplates } = require('../data/email_body.data'); -const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send'; -const GMAIL_PROFILE_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/profile'; +const GMAIL_SEND_URL = 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send'; // Lazily initialised so the module can be required before env is loaded. let _oauth2Client; @@ -85,10 +84,9 @@ const sendEmail = async ({ to, type, data = {} }) => { } }; -// Confirms the refresh token is valid and the Gmail API is reachable. -const ping = async () => { - const accessToken = await getAccessToken(); - await axios.get(GMAIL_PROFILE_URL, { headers: { Authorization: `Bearer ${accessToken}` } }); -}; +// Confirms the refresh token is valid and Gmail's OAuth endpoint is reachable. +// Deliberately doesn't call a Gmail read endpoint (e.g. users.getProfile) — the +// refresh token is scoped to gmail.send only, which doesn't grant read access. +const ping = () => getAccessToken(); module.exports = { sendEmail, ping };