diff --git a/src/backend/api/email/update-email-sent.js b/src/backend/api/email/update-email-sent.js index f9c3f42..a93cc82 100644 --- a/src/backend/api/email/update-email-sent.js +++ b/src/backend/api/email/update-email-sent.js @@ -4,9 +4,23 @@ import { sendEmail } from './helper'; export default async (req, res) => { const appID = req.body.id; - // send the actual email, then check if email sent correctly - if (req.body.accessToken) { - await sendEmail(req.body, req.body.accessToken); // TODO: check if accessToken sent securely. + const cookieHeader = req.headers?.cookie; + if (cookieHeader) { + const list = {}; + cookieHeader.split(';').forEach(cookie => { + let [name, ...rest] = cookie.split('='); + name = name?.trim(); + if (!name) return; + const value = rest.join('=').trim(); + if (!value) return; + list[name] = decodeURIComponent(value); + }); + console.log('cookieHeader::', list) + + // send the actual email, then check if email sent correctly + if (list.accessToken) { + await sendEmail(req.body, list.accessToken); // TODO: check if accessToken sent securely. + } } try { diff --git a/src/frontend/hooks/email.js b/src/frontend/hooks/email.js index 5646359..2d8b27c 100644 --- a/src/frontend/hooks/email.js +++ b/src/frontend/hooks/email.js @@ -2,7 +2,6 @@ import { useCallback } from 'react'; import { useDispatch } from 'react-redux'; import api from 'frontend/api'; import * as applicationActions from 'frontend/state/applications/actions'; -import CookiesHelper from './cookies.js'; const useEmail = () => { const dispatch = useDispatch(); @@ -10,12 +9,7 @@ const useEmail = () => { const updateEmailStatus = useCallback( async (emailData) => { try { - const { getCookie, CookieTags } = CookiesHelper; - const accessToken = getCookie(CookieTags.accessToken); - const res = await api.email.updateApplicationEmailSent({ - ...emailData, - accessToken, - }); + const res = await api.email.updateApplicationEmailSent(emailData); if (res.status !== 200) { throw new Error(