Merge branch 'develop' into feature/updated-user-type-dashboard

This commit is contained in:
Tiago Ribeiro
2023-10-22 09:42:45 +01:00
7 changed files with 53 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ interface MailOptions {
context: object;
}
export function prepareMailer(): nodemailer.Transporter {
export function prepareMailer(template?: string): nodemailer.Transporter {
const transport = nodemailer.createTransport({
host: process.env.SMTP_HOST,
auth: {
@@ -22,7 +22,7 @@ export function prepareMailer(): nodemailer.Transporter {
const handlebarOptions: hbs.NodemailerExpressHandlebarsOptions = {
viewEngine: {
partialsDir: path.resolve("src/email/templates"),
defaultLayout: "src/email/templates/main",
defaultLayout: `src/email/templates/${template || "main"}`,
},
viewPath: path.resolve("src/email/templates"),
};

View File

@@ -7,7 +7,7 @@
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<div style="background-color: #ffffff; color: #353338;"
class="h-full min-h-screen w-full flex flex-col p-8 gap-16 text-base" class="text-base">
class="h-full min-h-screen w-full flex flex-col p-8 gap-16 text-base">
<img src="/logo_title.png" class="w-48 h-48 self-center" />
<div>
<span>Hello future {{type}} of <b>EnCoach</b>,</span><br />

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<div>
<p>Hello {{name}},</p>
<br />
<p>Follow this link to verify your email address.</p>
<a href="https://platform.encoach.com/action?mode=signIn&continueUrl={{email}}&oobCode={{code}}">Verify account</a>
<br />
<br />
<p>If you didnt ask to verify this address, you can ignore this email.</p>
<br />
<p>Thanks,</p>
<p>Your EnCoach team</p>
</div>
</html>

View File

@@ -0,0 +1,5 @@
{
"name": "Tiago Ribeiro",
"email": "tiago.ribeiro@ecrop.dev",
"code": "123"
}

View File

@@ -4,21 +4,27 @@ import {getAuth as getAdminAuth, UserRecord} from "firebase-admin/auth";
import {app, adminApp} from "@/firebase";
import {sessionOptions} from "@/lib/session";
import {withIronSessionApiRoute} from "iron-session/next";
const auth = getAuth(app);
import {prepareMailer, prepareMailOptions} from "@/email";
import ShortUniqueId from "short-unique-id";
export default withIronSessionApiRoute(sendVerification, sessionOptions);
async function sendVerification(req: NextApiRequest, res: NextApiResponse) {
const short = new ShortUniqueId();
if (req.session.user) {
sendSignInLinkToEmail(auth, req.session.user.email, {
url: `https://platform.encoach.com/${req.session.user.email}`,
handleCodeInApp: true,
})
.then(() => res.status(200).json({ok: true}))
.catch((e) => {
console.log(e);
res.status(404).json({ok: false});
});
const transport = prepareMailer("verification");
const mailOptions = prepareMailOptions(
{
name: req.session.user.name,
code: short.randomUUID(6),
email: req.session.user.email,
},
[req.session.user.email],
"EnCoach Verification",
"verification",
);
await transport.sendMail(mailOptions);
}
}

View File

@@ -72,6 +72,9 @@ export default function Login() {
setIsLoading(true);
axios
.post<{ok: boolean}>("/api/reset/sendVerification", {})
.then(() => {
toast.success("An e-mail has been sent, please make sure to check your spam folder!");
})
.catch((e) => {
console.log(e);
toast.error("Something went wrong, please logout and re-login.", {toastId: "send-verify-error"});

View File

@@ -79,6 +79,9 @@ export default function Register({code: queryCode}: {code: string}) {
setIsLoading(true);
axios
.post<{ok: boolean}>("/api/reset/sendVerification", {})
.then(() => {
toast.success("An e-mail has been sent, please make sure to check your spam folder!");
})
.catch((e) => {
console.log(e);
toast.error("Something went wrong, please logout and re-login.", {toastId: "send-verify-error"});