Skip to content

Commit

Permalink
add email for cred collection notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Feb 20, 2025
1 parent 35b618a commit f36c8e7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
36 changes: 31 additions & 5 deletions app/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

import { z } from 'zod';
import { getVCFor } from './vc-templates/getVC';
import nodemailer from 'nodemailer'

const host = process.env.SMTP_HOST
const user = process.env.SMTP_USER
const pass = process.env.SMTP_PASS
const port = process.env.SMTP_PORT
const exchangeHost = process.env.EXCHANGE_HOST

const smtpOptions : any = {
host,
auth: { user, pass },
...(port && {port})
}

const transporter = nodemailer.createTransport(smtpOptions)

const FormSchema = z.object({
recipientName: z.string().trim()
.min(1, { message: "You must enter a name." }),
Expand Down Expand Up @@ -52,12 +65,10 @@ async function issueToLCW(vc:object):Promise<any> {
const result = await postData(`${exchangeHost}/exchange/setup`, dataToPost)
const deepLink = result[0];
const splitOnSlash = deepLink.directDeepLink.split('/')
console.log(splitOnSlash)
const transactionId = splitOnSlash.pop()
const exchangeId = splitOnSlash.pop()
deepLink.collectionPageURL = `${exchangeHost}/tryit/collect?exchangeId=${exchangeId}&transactionId=${transactionId}`
console.log("the result:")
console.log(result)
sendMail(`Your credential: ${deepLink.collectionPageURL}`, '[email protected]')
return {deepLink}
// the links could be emailed out. but show them here first.
}
Expand Down Expand Up @@ -96,8 +107,7 @@ export async function issueCredential(prevState: State, formData: FormData) {

const { delivery, revocable } = validatedFields.data;
const vc = getVCFor(validatedFields.data)
console.log("the vc:")
console.log(vc)


// Call the signing service
try {
Expand Down Expand Up @@ -132,4 +142,20 @@ async function postData(url = "", data = {}) {
return response.json();
}

async function sendMail(message:string, recipient:string) {
try {
const messageParams = {
from: process.env.EMAIL_FROM,
to: recipient,
subject: "You've got a credential!",
text: message
}
await transporter.sendMail(messageParams)
} catch (error) {
console.log('the email send error: ')
console.log(error)
}
}



2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"handlebars": "^4.7.8",
"next": "latest",
"next-auth": "5.0.0-beta.19",
"nodemailer": "^6.10.0",
"postcss": "8.4.49",
"react": "19.0.0",
"react-copy-to-clipboard": "^5.1.0",
Expand All @@ -28,6 +29,7 @@
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/node": "22.10.1",
"@types/nodemailer": "^6.4.17",
"@types/react": "19.0.0",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-dom": "19.0.0"
Expand Down
31 changes: 27 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f36c8e7

Please sign in to comment.