Merged PR 2317: Auth stabilisation: add reason-coded guards to MyPortal loaders

Adds incremental auth/session hardening across myportal loader paths (loadMyPortalAppealPage, searchresults, addresssearchresults) with explicit guard ordering and reason-coded diagnostics for missing session, missing session identity, missing cookie identity, contact/account lookup failures, and upstream dependency failures. Includes targeted Phase22 loader guard tests and keeps redirect behaviour policy unchanged.

Related work items: #23020
This commit is contained in:
Robert Bond
2026-05-14 10:27:12 +00:00
parent d0b2fd077a
commit 4fb62a6773
7 changed files with 532 additions and 24 deletions
+75 -5
View File
@@ -2,7 +2,7 @@ import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getIP } from "../../actions/core/logger";
import { consoleLogger, getIP } from "../../actions/core/logger";
import {
getPersonalAccount,
getPortalLogin
@@ -90,7 +90,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setShowReps(showReps, showLoginCheck));
if (!thisSession) {
console.log("not has sesssion.......");
consoleLogger({
name: "MyPortalSearchResultsAuthGuard",
reasonCode: "NO_SESSION",
message:
"myportal searchresults loader missing session; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
@@ -98,12 +103,77 @@ export const getServerSideProps = wrapper.getServerSideProps(
}
};
} else {
let loggedInUser = await getPortalLogin(thisSession.user.email);
if (!thisSession?.user?.id || !thisSession?.user?.email) {
consoleLogger({
name: "MyPortalSearchResultsAuthGuard",
reasonCode: "NO_SESSION_USER",
message:
"myportal searchresults loader missing session user identity; redirecting to signin",
hasSessionUserId: !!thisSession?.user?.id,
hasSessionUserEmail: !!thisSession?.user?.email
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
if (!cookies?.pinsUser) {
consoleLogger({
name: "MyPortalSearchResultsAuthGuard",
reasonCode: "NO_PINSUSER_COOKIE",
message:
"myportal searchresults loader missing pinsUser cookie; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
let loggedInUser;
try {
const portalLogin = await getPortalLogin(
thisSession.user.email
);
loggedInUser = portalLogin?.value?.[0]?.contactid;
} catch (error) {
consoleLogger({
name: "MyPortalSearchResultsAuthGuard",
reasonCode: "UPSTREAM_FAILURE",
message:
"myportal searchresults loader portal login lookup failed; redirecting to signin",
error: error?.message
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
if (!loggedInUser) {
consoleLogger({
name: "MyPortalSearchResultsAuthGuard",
reasonCode: "CONTACT_LOOKUP_FAILED",
message:
"myportal searchresults loader missing CRM contact id; redirecting to signin"
});
return {
redirect: {
destination: "/auth/signin",
permanent: false
}
};
}
//console.log("sssss", searchResultsObj);
loggedInUser = loggedInUser.value[0].contactid;
const watchedCases = await getWatchedCases(loggedInUser);
//console.log("sssss", loggedInUser);