-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Email templates and mail to all email addresses
- Loading branch information
1 parent
47b41c6
commit e532fca
Showing
11 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
|
||
const page = () => { | ||
return ( | ||
<div></div> | ||
) | ||
} | ||
|
||
export default page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
12 changes: 12 additions & 0 deletions
12
packages/prisma-db/prisma/migrations/20240613103822_email_template_added/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- CreateTable | ||
CREATE TABLE "EmailTemplate" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"from" TEXT NOT NULL, | ||
"subject" TEXT NOT NULL, | ||
"html" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "EmailTemplate_pkey" PRIMARY KEY ("id") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import db from './index' | ||
import {v4 as uuidv4} from 'uuid'; | ||
|
||
export const getEmailTemplateByName = async (name: string) => { | ||
try{ | ||
const emailTemplate = await db.emailTemplate.findFirst({ | ||
where:{name} | ||
}); | ||
return emailTemplate; | ||
} | ||
catch (error){ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
import {Resend} from 'resend'; | ||
import { getEmailTemplateByName } from '@repo/prisma-db/repo/email-template'; | ||
|
||
const resend = new Resend(process.env.RESEND_API_KEY) | ||
|
||
export const sendVerificationEmail = async (email: string, token:string) => { | ||
const confirmLink = `http://localhost:4000/auth/new-verification?token=${token}` | ||
|
||
const emailTemplate = await getEmailTemplateByName('verification-mail'); | ||
if (!emailTemplate) { | ||
return {error: "Verification Mail Template Not Found!"} | ||
} | ||
let html = emailTemplate.html; | ||
html = html.replace('{{confirmation_link}}', confirmLink); | ||
let from = emailTemplate.from; | ||
let subject = emailTemplate.subject; | ||
await resend.emails.send({ | ||
from: "[email protected]", | ||
from: from, | ||
to: email, | ||
subject: "Please confirm your email", | ||
html: `<p> | ||
Click <a href="${confirmLink}">here</a> to confirm your email | ||
</p>` | ||
subject: subject, | ||
html: html | ||
}) | ||
} | ||
|
||
|
||
export const sendResetEmail = async (email: string, token:string) => { | ||
const confirmLink = `http://localhost:4000/auth/reset-password?token=${token}` | ||
|
||
const emailTemplate = await getEmailTemplateByName('reset-password'); | ||
if (!emailTemplate) { | ||
return {error: "Email template not found!"} | ||
} | ||
let html = emailTemplate.html; | ||
html = html.replace('{{reset_password_link}}', confirmLink); | ||
let from = emailTemplate.from; | ||
let subject = emailTemplate.subject; | ||
await resend.emails.send({ | ||
from: "[email protected]", | ||
from: from, | ||
to: email, | ||
subject: "Reset your password", | ||
html: `<p> | ||
Click <a href="${confirmLink}">here</a> to modify your password | ||
</p>` | ||
subject: subject, | ||
html: html | ||
}) | ||
} |