added notify as email provider for nextauth

This commit is contained in:
2022-09-13 11:24:57 +01:00
parent 5529b2d5aa
commit e44f516eab
7 changed files with 48 additions and 97 deletions
+6 -6
View File
@@ -19,11 +19,11 @@ RELAYPATH = "dev-pedw-hc"
//Test Oauth ESNR //Test Oauth ESNR
CLIENT_ID = d40b9373-96c2-4b04-8bd8-c2a2fe6444c1 //CLIENT_ID = d40b9373-96c2-4b04-8bd8-c2a2fe6444c1
CLIENT_SECRET = IXI8Q~D5oqsC-nrtayHHc~tUAfjQFzNiKVQ~fc2S //CLIENT_SECRET = IXI8Q~D5oqsC-nrtayHHc~tUAfjQFzNiKVQ~fc2S
RELAY_ROOT = https://test-pedw-ns.servicebus.windows.net/test-pedw-hc/ //RELAY_ROOT = https://test-pedw-ns.servicebus.windows.net/test-pedw-hc/
RELAYURI = "test-pedw-ns.servicebus.windows.net" //RELAYURI = "test-pedw-ns.servicebus.windows.net"
RELAYPATH = "test-pedw-hc" //RELAYPATH = "test-pedw-hc"
//Preprod Oauth WGO //Preprod Oauth WGO
@@ -44,7 +44,7 @@ RELAYPATH = "test-pedw-hc"
GOOGLE_TAG_MANAGER = GTM-T78CBC3 GOOGLE_TAG_MANAGER = GTM-T78CBC3
SHOWLOGIN = "false" SHOWLOGIN = "true"
SHOWREPRESENTATIONS = false SHOWREPRESENTATIONS = false
SHOWFILEUPLOAD = "false" SHOWFILEUPLOAD = "false"
SHOWMAPS = "true" SHOWMAPS = "true"
+14 -7
View File
@@ -25,14 +25,21 @@ const MainHome = (props) => {
<div className="govuk-grid-row"> <div className="govuk-grid-row">
<div className="govuk-grid-column-full"> <div className="govuk-grid-column-full">
<div className="flex-container grid-row govuk-body "> <div className="flex-container grid-row govuk-body ">
{showLogin != "true" && <LoginSoon />} {showLogin != "true" && (
<CaseSearch /> <>
<LoginSoon />
<CaseSearch />
</>
)}
{showLogin == "true" && ( {showLogin == "true" && (
<Login <>
GG_CLIENT_ID={GG_CLIENT_ID} <CaseSearch />
GG_REDIRECT_URI={GG_REDIRECT_URI} <Login
session={session} GG_CLIENT_ID={GG_CLIENT_ID}
/> GG_REDIRECT_URI={GG_REDIRECT_URI}
session={session}
/>
</>
)}{" "} )}{" "}
<CaseComment /> <CaseComment />
<Dns /> <Dns />
+1
View File
@@ -52,6 +52,7 @@
"nextjs-basic-auth-middleware": "^0.2.1", "nextjs-basic-auth-middleware": "^0.2.1",
"nodemailer": "^6.7.8", "nodemailer": "^6.7.8",
"nookies": "^2.5.2", "nookies": "^2.5.2",
"notifications-node-client": "^5.1.1",
"ospoint": "^0.2.1", "ospoint": "^0.2.1",
"path": "^0.12.7", "path": "^0.12.7",
"react": "17.0.2", "react": "17.0.2",
+24 -81
View File
@@ -3,82 +3,10 @@ import EmailProvider from "next-auth/providers/email";
import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { PrismaClient } from "@prisma/client"; import { PrismaClient } from "@prisma/client";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { consoleLogger } from "../../../actions";
const prisma = new PrismaClient(); const prisma = new PrismaClient();
// async function sendVerificationRequest({
// identifier: email,
// url,
// provider: { server, from },
// }) {
// const { host } = new URL(url);
// const transport = nodemailer.createTransport(server);
// await transport.sendMail({
// to: email,
// from,
// subject: `Sign in to ${host}`,
// text: text({ url, host }),
// html: html({ url, host, email }),
// });
// }
// Email HTML body
function html({ url, host, email }) {
// Insert invisible space into domains and email address to prevent both the
// email address and the domain from being turned into a hyperlink by email
// clients like Outlook and Apple mail, as this is confusing because it seems
// like they are supposed to click on their email address to sign in.
const escapedEmail = `${email.replace(/\./g, "&#8203;.")}`;
const escapedHost = `${host.replace(/\./g, "&#8203;.")}`;
// Some simple styling options
const backgroundColor = "#ffffff";
const textColor = "#444444";
const mainBackgroundColor = "#ffffff";
const buttonBackgroundColor = "#aa1111";
const buttonBorderColor = "#aa1111";
const buttonTextColor = "#ffffff";
const headerBackgroundColor = "#000000";
return `
<body style="background: ${backgroundColor};">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="padding: 10px 0px 20px 0px; font-size: 22px; font-family: Helvetica, Arial, sans-serif; color: #fff;background-color: ${headerBackgroundColor};border-bottom: 10px solid #ffd530;>
<strong>PEDW - Planning Casework</strong>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="20" cellpadding="0" style="background: ${mainBackgroundColor}; max-width: 600px; margin: auto; border-radius: 10px;">
<tr>
<td align="center" style="padding: 10px 0px 0px 0px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: ${textColor};">
Sign in as <strong>${escapedEmail}</strong>
</td>
<img src ="http://localhost:3000/assets/images/planning-casework-en.svg"/>
</tr>
<tr>
<td align="center" style="padding: 20px 0;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="border-radius: 5px;" bgcolor="${buttonBackgroundColor}"><a href="${url}" target="_blank" style="font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: ${buttonTextColor}; text-decoration: none; border-radius: 5px; padding: 10px 20px; border: 1px solid ${buttonBorderColor}; display: inline-block; font-weight: bold;">Sign in</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" style="padding: 0px 0px 10px 0px; font-size: 16px; line-height: 22px; font-family: Helvetica, Arial, sans-serif; color: ${textColor};">
If you did not request this email you can safely ignore it.
</td>
</tr>
</table>
</body>
`;
}
// Email Text body (fallback for email clients that don't render HTML, e.g. feature phones)
function text({ url, host }) {
return `Sign in to PEDW - Planning Casework\n${url}\n\n`;
}
// For more information on each option (and a full list of options) go to // For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options // https://next-auth.js.org/configuration/options
export default NextAuth({ export default NextAuth({
@@ -101,14 +29,29 @@ export default NextAuth({
provider: { server, from }, provider: { server, from },
}) { }) {
const { host } = new URL(url); const { host } = new URL(url);
const transport = nodemailer.createTransport(server); const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661";
await transport.sendMail({ const emailAddress = email;
to: email, const personalisation = {
from, "emailAddress": email,
subject: `Sign in to PEDW - Planning Casework`, "signInLink": url,
text: text({ url, host }), "linkExpiry": 10 * 60,
html: html({ url, host, email }), };
}); const reference = "PEDW-SIGNIN";
var NotifyClient =
require("notifications-node-client").NotifyClient;
const notifyClient = new NotifyClient(
process.env.NOTIFY_API_KEY
);
await notifyClient
.sendEmail(templateId, emailAddress, {
personalisation: personalisation,
reference: reference,
// emailReplyToId: emailReplyToId,
})
.catch((err) => consoleLogger(err));
}, },
}), }),
], ],
@@ -34,7 +34,7 @@ export default async function ApiProxy(req, res) {
queryUrl = queryUrl; //+ getSelectQuery(appealTypeName); queryUrl = queryUrl; //+ getSelectQuery(appealTypeName);
//console.log("query: ", queryUrl, "<<<<end query"); //console.log("///////////\nquery: ", queryUrl, "<<<<end query");
return axios return axios
.get( .get(
@@ -34,7 +34,7 @@ export default async function ApiProxy(req, res) {
queryUrl = queryUrl + getSelectQuery(appealTypeName); queryUrl = queryUrl + getSelectQuery(appealTypeName);
console.log("query: ", queryUrl, "<<<<end query"); //console.log("///////////\nquery: ", queryUrl, "<<<<end query");
return axios return axios
.get( .get(
+1 -1
View File
@@ -26,7 +26,7 @@ export default async function ApiProxy(req, res) {
loggedInUserId + loggedInUserId +
" and servicestage eq 0 and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true&$top=3"; " and servicestage eq 0 and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true&$top=3";
//console.log("Portal query: ", queryUrl, "<<<<end query"); //console.log("///////////\nPortal query: ", queryUrl, "<<<<end query");
return axios return axios
.get( .get(