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:
@@ -3,7 +3,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 } from "../../actions/services/accountService";
|
||||
import { getPortalModuleDetails } from "../../actions/services/caseService";
|
||||
import {
|
||||
@@ -142,8 +142,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req } = ctx;
|
||||
getIP(req);
|
||||
const searchResultsObj = await getAddressSearch(query);
|
||||
const searchDetailsObj = searchResultsObj;
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
||||
store.dispatch(setShowReps(showReps, showLoginCheck));
|
||||
@@ -155,7 +153,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
let thisSession = await getSession(ctx);
|
||||
|
||||
if (!thisSession) {
|
||||
console.log("not has sesssion.......");
|
||||
consoleLogger({
|
||||
name: "MyPortalAddressSearchResultsAuthGuard",
|
||||
reasonCode: "NO_SESSION",
|
||||
message:
|
||||
"myportal addresssearchresults loader missing session; redirecting to signin"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
@@ -163,20 +166,91 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
};
|
||||
} else {
|
||||
if (!thisSession?.user?.id || !thisSession?.user?.email) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAddressSearchResultsAuthGuard",
|
||||
reasonCode: "NO_SESSION_USER",
|
||||
message:
|
||||
"myportal addresssearchresults loader missing session user identity; redirecting to signin",
|
||||
hasSessionUserId: !!thisSession?.user?.id,
|
||||
hasSessionUserEmail: !!thisSession?.user?.email
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!loggedInUser) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAddressSearchResultsAuthGuard",
|
||||
reasonCode: "NO_PINSUSER_COOKIE",
|
||||
message:
|
||||
"myportal addresssearchresults loader missing pinsUser cookie; redirecting to signin"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
thisSession != false &&
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
|
||||
const [accountDetails, searchResultsObj, watchedCases] =
|
||||
await Promise.all([
|
||||
getPersonalAccount(loggedInUser),
|
||||
getAdvancedSearch(query),
|
||||
getWatchedCases(loggedInUser)
|
||||
]);
|
||||
let accountDetails;
|
||||
let searchResultsObj;
|
||||
let watchedCases;
|
||||
let searchDetailsObj;
|
||||
let watchedCasesDetails;
|
||||
|
||||
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
|
||||
getSearchDetails(searchResultsObj),
|
||||
getDetails(watchedCases, "myWatchedCases")
|
||||
]);
|
||||
try {
|
||||
[accountDetails, searchResultsObj, watchedCases] =
|
||||
await Promise.all([
|
||||
getPersonalAccount(loggedInUser),
|
||||
getAdvancedSearch(query),
|
||||
getWatchedCases(loggedInUser)
|
||||
]);
|
||||
|
||||
[searchDetailsObj, watchedCasesDetails] = await Promise.all([
|
||||
getSearchDetails(searchResultsObj),
|
||||
getDetails(watchedCases, "myWatchedCases")
|
||||
]);
|
||||
} catch (error) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAddressSearchResultsAuthGuard",
|
||||
reasonCode: "UPSTREAM_FAILURE",
|
||||
message:
|
||||
"myportal addresssearchresults loader dependency call failed; redirecting to signin",
|
||||
error: error?.message
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!accountDetails || accountDetails?.errorCode) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAddressSearchResultsAuthGuard",
|
||||
reasonCode: "CONTACT_LOOKUP_FAILED",
|
||||
message:
|
||||
"myportal addresssearchresults loader account lookup failed; redirecting to signin",
|
||||
hasAccountDetails: !!accountDetails,
|
||||
hasErrorCode: !!accountDetails?.errorCode
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setSearchResults(searchResultsObj));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user