Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/backend/api/email/update-email-sent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 1 addition & 7 deletions src/frontend/hooks/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ 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();

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(
Expand Down