Merged PR 2315: Auth stabilistatiion and hardening
Related work items: #23020
This commit is contained in:
@@ -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
|
||||
@@ -46,7 +46,6 @@ const Home = (props) => {
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
const { appealtypes } = router.query;
|
||||
|
||||
return (
|
||||
@@ -79,44 +78,98 @@ const Home = (props) => {
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
const { query, req } = ctx;
|
||||
getIP(req);
|
||||
console.log("query-", query);
|
||||
//console.log("search array:", Object.entries(query));
|
||||
const { cookies } = req;
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
|
||||
let thisSession = await getSession(ctx);
|
||||
|
||||
let loggedInUser = await getPortalLogin(thisSession.user.email);
|
||||
|
||||
if (!thisSession) {
|
||||
console.log("not has sesssion.......");
|
||||
consoleLogger({
|
||||
name: "MyPortalAdvancedSearchResultsAuthGuard",
|
||||
reasonCode: "NO_SESSION",
|
||||
message:
|
||||
"advancedsearchresults loader missing session; redirecting to signin"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
} else {
|
||||
}
|
||||
|
||||
if (!thisSession?.user?.email || !thisSession?.user?.id) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAdvancedSearchResultsAuthGuard",
|
||||
reasonCode: "NO_SESSION_USER",
|
||||
message:
|
||||
"advancedsearchresults loader missing session user identity; redirecting to signin",
|
||||
hasSessionUserEmail: !!thisSession?.user?.email,
|
||||
hasSessionUserId: !!thisSession?.user?.id
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let loggedInUser;
|
||||
try {
|
||||
const loggedInUserLookup = await getPortalLogin(
|
||||
thisSession.user.email
|
||||
);
|
||||
loggedInUser = loggedInUserLookup?.value?.[0]?.contactid;
|
||||
} catch (error) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAdvancedSearchResultsAuthGuard",
|
||||
reasonCode: "UPSTREAM_FAILURE",
|
||||
message:
|
||||
"advancedsearchresults loader portal login lookup failed; redirecting to signin",
|
||||
error: error?.message
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (!loggedInUser) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAdvancedSearchResultsAuthGuard",
|
||||
reasonCode: "CONTACT_LOOKUP_FAILED",
|
||||
message:
|
||||
"advancedsearchresults loader missing CRM contact id; redirecting to signin"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
thisSession != false &&
|
||||
store.dispatch(setContainerID(thisSession.user.id));
|
||||
|
||||
loggedInUser = await getPortalLogin(thisSession.user.email);
|
||||
|
||||
loggedInUser = loggedInUser.value[0].contactid;
|
||||
|
||||
const [accountDetails, watchedCases] = await Promise.all([
|
||||
await getPersonalAccount(loggedInUser),
|
||||
await getWatchedCases(loggedInUser)
|
||||
getPersonalAccount(loggedInUser),
|
||||
getWatchedCases(loggedInUser)
|
||||
]);
|
||||
|
||||
console.log(accountDetails);
|
||||
|
||||
const [watchedCasesDetails] = await Promise.all([
|
||||
await getDetails(watchedCases, "myWatchedCases")
|
||||
]);
|
||||
const watchedCasesDetails = await getDetails(
|
||||
watchedCases,
|
||||
"myWatchedCases"
|
||||
);
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
const showReps = process.env.SHOWREPRESENTATIONS || false;
|
||||
@@ -127,7 +180,22 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
store.dispatch(setSearch(Object.entries(query)));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
} catch (error) {
|
||||
consoleLogger({
|
||||
name: "MyPortalAdvancedSearchResultsAuthGuard",
|
||||
reasonCode: "UPSTREAM_FAILURE",
|
||||
message:
|
||||
"advancedsearchresults loader dependency failure; redirecting to signin",
|
||||
error: error?.message
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
showLoginCheck: showLoginCheck
|
||||
@@ -139,7 +207,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
const getDetails = (resultsObj, detailsType) => {
|
||||
let detailsArr = [];
|
||||
resultsObj = resultsObj.value;
|
||||
const detailsObj = resultsObj.map((searchDetail, index) => {
|
||||
const detailsObj = resultsObj.map((searchDetail) => {
|
||||
if (searchDetail.pinswg_appealcasetype == null) {
|
||||
console.log(
|
||||
detailsType != "myWatchedCases"
|
||||
|
||||
Reference in New Issue
Block a user