import NextAuth from "next-auth"; import EmailProvider from "next-auth/providers/email"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { PrismaClient } from "@prisma/client"; import nodemailer from "nodemailer"; import { consoleLogger } from "../../../actions"; const prisma = new PrismaClient(); // For more information on each option (and a full list of options) go to // https://next-auth.js.org/configuration/options export default NextAuth({ // https://next-auth.js.org/configuration/providers providers: [ EmailProvider({ server: { host: process.env.EMAIL_SERVER_HOST, port: process.env.EMAIL_SERVER_PORT, auth: { user: process.env.EMAIL_SERVER_USER, pass: process.env.EMAIL_SERVER_PASSWORD, }, }, from: process.env.EMAIL_FROM, maxAge: 10 * 60, // Magic links are valid for 10 min only async sendVerificationRequest({ identifier: email, url, provider: { server, from }, }) { const { host } = new URL(url); const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661"; const emailAddress = email; const personalisation = { "emailAddress": email, "signInLink": url, "linkExpiry": 10 * 60, }; 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)); }, }), ], adapter: PrismaAdapter(prisma), secret: process.env.SECRET, session: { jwt: true, pages: {}, theme: "dark", debug: true, }, pages: { signIn: "/auth/signin", //signOut: "/auth/signout", error: "/auth/error", // Error code passed in query string as ?error= verifyRequest: "/auth/verify-request", // (used for check email message) newUser: "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest) }, callbacks: { session: async (session, user) => { console.log(user); return Promise.resolve(session); }, }, });