Merged PR 2665: 25470 testing authentication handler

Related work items: #25470
This commit is contained in:
Robert Bond
2026-11-02 12:41:09 +00:00
parent ce21a1a00f
commit 93eabe8e6d
6 changed files with 581 additions and 37 deletions
+46 -1
View File
@@ -19,6 +19,40 @@ import { getPortalLogin } from "../../../actions/services/accountService";
const prisma = new PrismaClient();
const createVerificationTokenCompletion = () => {
let complete;
const promise = new Promise((resolve) => {
complete = resolve;
});
return { promise, complete };
};
const createVerificationTokenSynchronizationAdapter = (
verificationTokenCompletion
) => {
const adapter = PrismaAdapter(prisma);
return {
...adapter,
async createVerificationToken(data) {
try {
const result = await adapter.createVerificationToken(data);
verificationTokenCompletion.complete({ result });
return result;
} catch (error) {
verificationTokenCompletion.complete({ error });
throw error;
}
}
};
};
const WELSH_LANGUAGE_CODE = 846040000;
const authDiagnostic = (event, metadata = {}) => {
@@ -167,6 +201,7 @@ const resolveRequestLocale = (req) => {
const authOptions = (req, res) => {
const requestLocale = resolveRequestLocale(req);
const verificationTokenCompletion = createVerificationTokenCompletion();
return {
providers: [
@@ -186,6 +221,13 @@ const authOptions = (req, res) => {
effectiveLocale
});
const tokenCreation =
await verificationTokenCompletion.promise;
if (tokenCreation.error) {
throw tokenCreation.error;
}
return res
.writeHead(200, { "Content-Type": "application/json" })
.json({ url: formURL });
@@ -240,7 +282,10 @@ const authOptions = (req, res) => {
}
})
],
adapter: PrismaAdapter(prisma),
adapter: createVerificationTokenSynchronizationAdapter(
verificationTokenCompletion
),
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "database",
+27 -8
View File
@@ -317,11 +317,11 @@ export const getServerSideProps = wrapper.getServerSideProps(
const limitRequests = pLimit(5);
const arr = [];
const list =
detailsType === "mySubmittedReps"
? resultsObj
: resultsObj.value;
const list = resultsObj.value;
// detailsType === "mySubmittedReps"
// ? resultsObj
// : resultsObj.value;
// console.log(list);
const tasks = list.map((item) =>
limitRequests(async () => {
try {
@@ -374,18 +374,37 @@ export const getServerSideProps = wrapper.getServerSideProps(
return arr;
};
const DASHBOARD_LIMIT = 3;
const limitResults = (data) => ({
...data,
value: (data?.value ?? []).slice(0, DASHBOARD_LIMIT)
});
const [
myCasesDetails,
watchedCasesDetails,
mySubmittedRepsDetails,
myRepresentationsDetails
] = await Promise.all([
getDetails(myCases, "myCases"),
getDetails(filteredWatchedCases, "myWatchedCases"),
getDetails(mySubmittedReps, "mySubmittedReps"),
getDetails(limitResults(myCases), "myCases"),
getDetails(limitResults(filteredWatchedCases), "myWatchedCases"),
getDetails(limitResults(mySubmittedReps), "mySubmittedReps"),
getDetails(myRepresentations, "myRepresentations")
]);
// const [
// myCasesDetails,
// watchedCasesDetails,
// mySubmittedRepsDetails,
// myRepresentationsDetails
// ] = await Promise.all([
// getDetails(limitResults(myCases), "myCases"),
// getDetails(limitResults(filteredWatchedCases), "myWatchedCases"),
// getDetails(limitResults(mySubmittedReps), "mySubmittedReps"),
// getDetails(limitResults(myRepresentations), "myRepresentations")
// ]);
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setMyCases(myCases));
+327 -10
View File
@@ -11,7 +11,63 @@ import ViewAll from "../../components/myportal/viewall";
import NoSessionWarning from "../../components/nosession";
import TimeOut from "../../components/timeout";
import ServiceBanner from "../../components/myportal/servicebanner";
import { getSession } from "next-auth/react";
import pLimit from "p-limit";
import {
getPersonalAccount,
getPortalLogin
} from "../../actions/services/accountService";
import { getPortalModuleDetails } from "../../actions/services/caseService";
import {
getAwaitingSubmissionFromBlob,
getRepsFromBlob
} from "../../actions/services/documentService";
import {
getMyCases,
getMyLPACases,
getWatchedCases
} from "../../actions/services/portalService";
import { getBasicSearch } from "../../actions/services/searchService";
import { splitWatchedCasesBySubmissionState } from "../../lib/domain/dashboard-policy";
import { getFormCollectionByID } from "../../components/utils";
import {
setAccountDetails,
setContainerID,
setLoggedInUserId
} from "../../store/accountDetails/action";
import {
setAwaitingSubmissionDetails,
setAwaitingSubmissionFromBlob
} from "../../store/awaitingSubmission/action";
import { setCurrentView } from "../../store/currentView/action";
import { setMyCases, setMyCasesDetails } from "../../store/myCases/action";
import {
setMyRepresentations,
setMyRepresentationsDetails,
setMySubmittedReps,
setMySubmittedRepsDetails
} from "../../store/myRepresentations/action";
import {
setWatchedCases,
setWatchedCasesDetails
} from "../../store/watchedCases/action";
import { setSearchResults } from "../../store/searchOutput/action";
import { setSearch } from "../../store/search/action";
import { wrapper } from "../../store/store";
const Home = (props) => {
const { footerLinks, pages } = props;
let { t, lang } = useTranslation();
@@ -39,7 +95,7 @@ const Home = (props) => {
),
"myRepresentations": t("common:myrepresentations-viewall-title"),
"watchedCases": t("common:watchedcases-viewall-title"),
"mySubmittedReps": t("common:mysubmittedreps-viewall-title"),
"mySubmittedReps": t("common:mysubmittedreps-viewall-title")
};
function whichTitle(key) {
@@ -83,14 +139,275 @@ const Home = (props) => {
);
};
// export const getServerSideProps = wrapper.getServerSideProps(
// (store) =>
// async ({ req, res }) => {
// const searchResultsObj = (await getBasicSearch("View All")) || null;
// store.dispatch(setSearchResults(searchResultsObj));
// store.dispatch(setSearch("View All"));
// }
// );
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query } = ctx;
// The View All component uses router.query.key.
const viewKey = Array.isArray(query.key) ? query.key[0] : query.key;
console.log("[ViewAll SSR] Query:", ctx.query);
console.log("[ViewAll SSR] Selected viewKey:", viewKey);
const validViewKeys = [
"myCases",
"watchedCases",
"mySubmittedReps",
"myRepresentations",
"awaitingSubmissionDetails"
];
if (!validViewKeys.includes(viewKey)) {
return {
redirect: {
destination: "/myportal",
permanent: false
}
};
}
// Authenticate before retrieving portal data.
const thisSession = await getSession(ctx);
if (!thisSession?.user?.email) {
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
const portalLogin = await getPortalLogin(thisSession.user.email);
const loggedInUser = portalLogin?.value?.[0]?.contactid;
if (!loggedInUser) {
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
const accountDetails = await getPersonalAccount(loggedInUser);
if (!accountDetails || accountDetails.errorCode) {
return {
redirect: {
destination: "/myportal/error",
permanent: false
}
};
}
// Preserve the LPA logic from MyPortal index.
const isLPA = accountDetails.pinswg_typeofinvolvement === 846040012;
const lpaId =
accountDetails[
"pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue"
];
// Full-list detail enrichment.
// No dashboard limit is applied here.
const getDetails = async (resultsObj, detailsType) => {
const limitRequests = pLimit(5);
const list = Array.isArray(resultsObj)
? resultsObj
: (resultsObj?.value ?? []);
const tasks = list.map((item) =>
limitRequests(async () => {
try {
let caseID = "";
switch (detailsType) {
case "myCases":
caseID = item.ticketnumber;
break;
case "myWatchedCases":
case "mySubmittedReps":
caseID =
item[
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
];
break;
case "awaitingSubmission":
caseID = item.ticketnumber;
break;
case "myRepresentations":
caseID = item.casereference;
break;
default:
caseID = item.pinswg_title;
}
if (!item.pinswg_appealcasetype || !caseID) {
return null;
}
const formCollection = getFormCollectionByID(
item.pinswg_appealcasetype
);
if (!formCollection?.LogicalCollectionName) {
console.error(
"Missing collection metadata for appeal type:",
item.pinswg_appealcasetype
);
return null;
}
return (
(await getPortalModuleDetails(
formCollection.LogicalCollectionName,
caseID
)) || {}
);
} catch (err) {
console.error("Error fetching View All details:", err);
return null;
}
})
);
const details = await Promise.all(tasks);
// Retain the original result ordering.
return details.filter(Boolean);
};
// Shared account state.
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setContainerID(thisSession.user.id));
// Ensure the rendered View All category agrees
// with the category loaded by this request.
store.dispatch(
setCurrentView({
viewKey,
viewName: viewKey
})
);
switch (viewKey) {
case "myCases": {
const myCases = isLPA
? await getMyLPACases(lpaId)
: await getMyCases(loggedInUser);
const myCasesDetails = await getDetails(myCases, "myCases");
store.dispatch(setMyCases(myCases));
store.dispatch(setMyCasesDetails(myCasesDetails));
break;
}
case "watchedCases": {
const watchedCases = await getWatchedCases(loggedInUser);
const { watchedCases: filteredWatchedCases } =
splitWatchedCasesBySubmissionState(
watchedCases.value ?? []
);
const watchedCasesDetails = await getDetails(
filteredWatchedCases,
"myWatchedCases"
);
store.dispatch(setWatchedCases(filteredWatchedCases));
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
break;
}
case "mySubmittedReps": {
const watchedCases = await getWatchedCases(loggedInUser);
const { submittedRepresentations: mySubmittedReps } =
splitWatchedCasesBySubmissionState(
watchedCases.value ?? []
);
const mySubmittedRepsDetails = await getDetails(
mySubmittedReps,
"mySubmittedReps"
);
store.dispatch(setMySubmittedReps(mySubmittedReps));
store.dispatch(
setMySubmittedRepsDetails(mySubmittedRepsDetails)
);
break;
}
case "myRepresentations": {
const myRepresentations = await getRepsFromBlob(
thisSession.user.id
);
// The existing View All component reads
// representation display data directly
// from myRepresentations.value.
store.dispatch(setMyRepresentations(myRepresentations));
// Preserve the existing Redux detail
// collection contract.
const myRepresentationsDetails = await getDetails(
myRepresentations,
"myRepresentations"
);
store.dispatch(
setMyRepresentationsDetails(myRepresentationsDetails)
);
break;
}
case "awaitingSubmissionDetails": {
const awaitingSubmissionFromBlob =
await getAwaitingSubmissionFromBlob(thisSession.user.id);
// Awaiting submission already has its
// own Blob-backed data structure.
// Preserve the dashboard's existing
// Redux dispatches.
store.dispatch(
setAwaitingSubmissionFromBlob(awaitingSubmissionFromBlob)
);
store.dispatch(
setAwaitingSubmissionDetails(awaitingSubmissionFromBlob)
);
break;
}
}
// Preserve the original View All search state.
const searchResultsObj = (await getBasicSearch("View All")) || null;
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearch("View All"));
return {
props: {}
};
}
);
const mapStateToProps = (state) => {
return {
@@ -105,7 +422,7 @@ const mapStateToProps = (state) => {
myRepresentations: state.myRepresentations,
awaitingSubmission: state.awaitingSubmission,
currentView: state.currentView,
mySubmittedReps: state.myRepresentations.mySubmittedReps,
mySubmittedReps: state.myRepresentations.mySubmittedReps
};
};