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
248 lines
8.6 KiB
JavaScript
248 lines
8.6 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import Head from "next/head";
|
|
import { useRouter } from "next/router";
|
|
import { connect } from "react-redux";
|
|
import { consoleLogger, getIP } from "../../actions/core/logger";
|
|
import {
|
|
getPersonalAccount,
|
|
getPortalLogin
|
|
} from "../../actions/services/accountService";
|
|
import { getPortalModuleDetails } from "../../actions/services/caseService";
|
|
import { getBasicSearch } from "../../actions/services/searchService";
|
|
import { getWatchedCases } from "../../actions/services/portalService";
|
|
import Breadcrumbs from "../../components/breadcrumbs";
|
|
import CookieBanner from "../../components/cookieBanner";
|
|
import Footer from "../../components/footer";
|
|
import Header from "../../components/header";
|
|
import SearchResults from "../../components/searchresults";
|
|
import {
|
|
getFormCollectionByID,
|
|
getSearchDetails
|
|
} from "../../components/utils";
|
|
import { setShowReps } from "../../store/currentView/action";
|
|
import { setSearch } from "../../store/search/action";
|
|
import {
|
|
setSearchDetails,
|
|
setSearchResults
|
|
} from "../../store/searchOutput/action";
|
|
import { wrapper } from "../../store/store";
|
|
import {
|
|
setWatchedCases,
|
|
setWatchedCasesDetails
|
|
} from "../../store/watchedCases/action";
|
|
|
|
import { getSession } from "next-auth/react";
|
|
import TimeOut from "../../components/timeout";
|
|
import {
|
|
setAccountDetails,
|
|
setContainerID,
|
|
setLoggedInUserId
|
|
} from "../../store/accountDetails/action";
|
|
import ServiceBanner from "../../components/myportal/servicebanner";
|
|
|
|
const Home = (props) => {
|
|
const { footerLinks, pages, watchedCases, showLoginCheck } = props;
|
|
let { t, lang } = useTranslation();
|
|
|
|
const router = useRouter();
|
|
const { locale } = router;
|
|
const { appealtypes } = router.query;
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>
|
|
{t("search:page-title")} - {t("common:service-name")}
|
|
</title>
|
|
</Head>
|
|
<div id="page_wrapper">
|
|
<CookieBanner />
|
|
<Header />
|
|
<div className="govuk-width-container">
|
|
<Breadcrumbs slug={appealtypes} />{" "}
|
|
<ServiceBanner props={props} />
|
|
<SearchResults
|
|
searchString={props.search.searchString}
|
|
searchResultsObj={props.searchResultsObj}
|
|
myportal={true}
|
|
watchedCases={watchedCases}
|
|
/>
|
|
</div>
|
|
<Footer footerLinks={footerLinks} ticketnumber={props} />
|
|
</div>
|
|
<TimeOut />
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = wrapper.getServerSideProps(
|
|
(store) => async (ctx) => {
|
|
const { query, req } = ctx;
|
|
getIP(req);
|
|
console.log("query-", query);
|
|
|
|
const { cookies } = req;
|
|
|
|
let thisSession = await getSession(ctx);
|
|
|
|
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
|
const showLoginCheck = process.env.SHOWLOGIN || false;
|
|
store.dispatch(setShowReps(showReps, showLoginCheck));
|
|
|
|
if (!thisSession) {
|
|
consoleLogger({
|
|
name: "MyPortalSearchResultsAuthGuard",
|
|
reasonCode: "NO_SESSION",
|
|
message:
|
|
"myportal searchresults loader missing session; redirecting to signin"
|
|
});
|
|
return {
|
|
redirect: {
|
|
destination: "/auth/signin",
|
|
permanent: false
|
|
}
|
|
};
|
|
} else {
|
|
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);
|
|
|
|
const watchedCases = await getWatchedCases(loggedInUser);
|
|
|
|
//console.log("sssss", loggedInUser);
|
|
|
|
const [accountDetails, watchedCasesDetails] = await Promise.all([
|
|
getPersonalAccount(loggedInUser),
|
|
getDetails(watchedCases, "myWatchedCases")
|
|
]);
|
|
store.dispatch(setAccountDetails(accountDetails));
|
|
store.dispatch(setSearch(query.q));
|
|
store.dispatch(setWatchedCases(watchedCases));
|
|
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
|
store.dispatch(setLoggedInUserId(loggedInUser));
|
|
|
|
thisSession != false &&
|
|
store.dispatch(setContainerID(thisSession.user.id));
|
|
}
|
|
return {
|
|
props: {
|
|
showLoginCheck: showLoginCheck
|
|
}
|
|
};
|
|
}
|
|
);
|
|
|
|
const getDetails = (resultsObj, detailsType) => {
|
|
let detailsArr = [];
|
|
resultsObj = resultsObj.value;
|
|
const detailsObj = resultsObj.map((searchDetail) => {
|
|
if (searchDetail.pinswg_appealcasetype == null) {
|
|
console.log(
|
|
detailsType != "myWatchedCases"
|
|
? searchDetail.ticketnumber
|
|
: searchDetail[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
);
|
|
} else {
|
|
detailsArr.push(
|
|
getPortalModuleDetails(
|
|
getFormCollectionByID(searchDetail.pinswg_appealcasetype)
|
|
.LogicalCollectionName,
|
|
detailsType != "myWatchedCases"
|
|
? searchDetail.ticketnumber
|
|
: searchDetail[
|
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
)
|
|
);
|
|
}
|
|
});
|
|
return Promise.all(detailsArr);
|
|
};
|
|
|
|
const mapStateToProps = (state) => {
|
|
return {
|
|
currentView: state.currentView,
|
|
search: state.search,
|
|
searchResultsObj: state.searchResultsObj,
|
|
formData: state.formData,
|
|
appealType: state.appealType,
|
|
form: state.form,
|
|
myCases: state.myCases,
|
|
watchedCases: state.watchedCases,
|
|
myRepresentations: state.myRepresentations,
|
|
awaitingSubmission: state.awaitingSubmission,
|
|
accountDetails: state.accountDetails
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(Home);
|