refactor phase 3a api admin auth documents email targeted actions imports

This commit is contained in:
2026-03-12 09:58:39 +00:00
parent cf99d8e466
commit 7bd5c7d833
9 changed files with 65 additions and 63 deletions
+15 -14
View File
@@ -14,7 +14,8 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import NextAuth from "next-auth";
import EmailProvider from "next-auth/providers/email";
import { consoleLogger, getPreferredLanguage } from "../../../actions";
import { consoleLogger } from "../../../actions/core/logger";
import { getPreferredLanguage } from "../../../actions/services/accountService";
const prisma = new PrismaClient();
@@ -43,7 +44,7 @@ const parseUrl = (url) => {
host: _url.host,
path,
base,
toString: () => base,
toString: () => base
};
};
@@ -127,7 +128,7 @@ const authOptions = (locale, req, res) => {
return res
.writeHead(200, { "Content-Type": "application/json" })
.json({ url: formURL });
},
}
},
EmailProvider({
maxAge: 2 * 60 * 60, //10 * 60, // Magic links are valid for 10 min only
@@ -191,7 +192,7 @@ const authOptions = (locale, req, res) => {
// url.split("&token")[1]
// : url,
"linkExpiry": 2 * 60 * 60,
"linkExpiry": 2 * 60 * 60
};
const reference = "PEDW-SIGNIN";
@@ -208,14 +209,14 @@ const authOptions = (locale, req, res) => {
emailAddress,
{
personalisation: personalisation,
reference: reference,
reference: reference
// emailReplyToId: emailReplyToId,
}
)
//.then((response) => console.log(response))
.catch((error) => consoleLogger(error));
},
}),
}
})
],
adapter: PrismaAdapter(prisma),
secret: process.env.NEXTAUTH_SECRET,
@@ -226,7 +227,7 @@ const authOptions = (locale, req, res) => {
theme: "dark",
debug: true,
maxAge: 30 * 60,
updateAge: 5 * 60, // 24 hours
updateAge: 5 * 60 // 24 hours
},
cookies: {
callbackUrl: {
@@ -234,16 +235,16 @@ const authOptions = (locale, req, res) => {
options: {
sameSite: "lax",
path: "/",
secure: true,
},
},
secure: true
}
}
},
pages: {
signIn: (locale == "cy" ? "/cy" : "") + "/auth/signin",
error: (locale == "cy" ? "/cy" : "") + "/auth/error", // Error code passed in query string as ?error=
verifyRequest:
(locale == "cy" ? "/cy" : "") + "/auth/verify-request", // (used for check email message)
newUser: (locale == "cy" ? "/cy" : "") + "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest)
newUser: (locale == "cy" ? "/cy" : "") + "/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) => {
@@ -275,8 +276,8 @@ const authOptions = (locale, req, res) => {
console.log("the url:", updatedUrl);
return updatedUrl;
},
},
}
}
};
};