diff --git a/apps/builder/pages/api/integrations/email/test-config.ts b/apps/builder/pages/api/integrations/email/test-config.ts index 188e63c46..1f71cdb61 100644 --- a/apps/builder/pages/api/integrations/email/test-config.ts +++ b/apps/builder/pages/api/integrations/email/test-config.ts @@ -1,9 +1,13 @@ -import { withSentry } from '@sentry/nextjs' +import { captureException, withSentry } from '@sentry/nextjs' import { SmtpCredentialsData } from 'models' import { NextApiRequest, NextApiResponse } from 'next' import { createTransport } from 'nodemailer' +import { getAuthenticatedUser } from 'services/api/utils' +import { notAuthenticated } from 'utils' const handler = async (req: NextApiRequest, res: NextApiResponse) => { + const user = await getAuthenticatedUser(req) + if (!user) return notAuthenticated(res) if (req.method === 'POST') { const { from, port, isTlsEnabled, username, password, host, to } = ( typeof req.body === 'string' ? JSON.parse(req.body) : req.body @@ -26,6 +30,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { }) res.status(200).send({ message: 'Email sent!', info }) } catch (err) { + captureException(err) console.log(err) res.status(500).send(err) } diff --git a/apps/builder/services/api/utils.ts b/apps/builder/services/api/utils.ts index dd8740f65..abc374bf2 100644 --- a/apps/builder/services/api/utils.ts +++ b/apps/builder/services/api/utils.ts @@ -1,3 +1,4 @@ +import { setUser } from '@sentry/nextjs' import { User } from 'db' import { NextApiRequest } from 'next' import { getSession } from 'next-auth/react' @@ -7,5 +8,7 @@ export const getAuthenticatedUser = async ( ): Promise => { const session = await getSession({ req }) if (!session?.user || !('id' in session.user)) return + const user = session.user as User + setUser({ id: user.id, email: user.email ?? undefined }) return session?.user as User }