updated authentication on protected pages

This commit is contained in:
2023-06-05 12:00:28 +01:00
parent 3dd4525770
commit 31375a5999
20 changed files with 408 additions and 119 deletions
+10
View File
@@ -223,6 +223,16 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
}
let loggedInUserIdent = thisSession.user.id;
let loggedInUserEmail = thisSession.user.email;
+25 -13
View File
@@ -75,22 +75,34 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
const [accountDetails, appealTypeData, lpaData] = await Promise.all([
await getPersonalAccount(loggedInUser),
await getAppealsTypes(),
await getLPA(),
]);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
const [accountDetails, appealTypeData, lpaData] = await Promise.all(
[
await getPersonalAccount(loggedInUser),
await getAppealsTypes(),
await getLPA(),
]
);
// const lpaData = require("../../data/lpa.json");
// const appealTypeData = require("../../data/appealtypes.json");
// const lpaData = require("../../data/lpa.json");
// const appealTypeData = require("../../data/appealtypes.json");
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id));
thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id));
}
}
);
+30 -20
View File
@@ -81,29 +81,39 @@ export const getServerSideProps = wrapper.getServerSideProps(
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id));
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id));
const [accountDetails, searchResultsObj, watchedCases] =
await Promise.all([
await getPersonalAccount(loggedInUser),
await getAdvancedSearch(query),
await getWatchedCases(loggedInUser),
const [accountDetails, searchResultsObj, watchedCases] =
await Promise.all([
await getPersonalAccount(loggedInUser),
await getAdvancedSearch(query),
await getWatchedCases(loggedInUser),
]);
console.log(accountDetails);
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
await getSearchDetails(searchResultsObj),
await getDetails(watchedCases, "myWatchedCases"),
]);
console.log(accountDetails);
const [searchDetailsObj, watchedCasesDetails] = await Promise.all([
await getSearchDetails(searchResultsObj),
await getDetails(watchedCases, "myWatchedCases"),
]);
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
store.dispatch(setWatchedCases(watchedCases));
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setSearch(Object.entries(query)));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
store.dispatch(setWatchedCases(watchedCases));
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setSearch(Object.entries(query)));
}
}
);
+13
View File
@@ -8,6 +8,8 @@ import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import TimeOut from "../../components/timeout";
import { useSession, getSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => {
const { footerLinks, pages, showRepresentations } = props;
@@ -17,6 +19,17 @@ const Home = (props) => {
const { locale } = router;
const { appealtypes } = router.query;
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+23 -9
View File
@@ -30,6 +30,8 @@ import {
setWatchedCasesDetails,
} from "../../store/watchedCases/action";
import { getSession, useSession } from "next-auth/react";
const Home = (props) => {
const { footerLinks, pages, watchedCases, showMap } = props;
let { t, lang } = useTranslation();
@@ -126,19 +128,30 @@ const Home = (props) => {
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async ({ query, req, res }) => {
console.log("query-", query);
(store) => async (ctx) => {
const { query, req, res } = ctx;
console.log("query-", query);
const { cookies } = req;
const { cookies } = req;
res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=59"
);
res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=59"
);
let loggedInUser = cookies.pinsUser;
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
let [searchResultsObj, watchedCases] = await Promise.all([
await getBasicDNSSearch(),
await getWatchedCases(loggedInUser),
@@ -170,6 +183,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
props: { showMap: showMapCheck },
};
}
}
);
const getDetails = (resultsObj, detailsType) => {
+12
View File
@@ -7,6 +7,7 @@ import Case from "../../components/case";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import { useSession, getSession } from "next-auth/react";
const Home = (props) => {
const { footerLinks, pages } = props;
@@ -16,6 +17,17 @@ const Home = (props) => {
const { locale } = router;
const { appealtypes } = router.query;
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+26
View File
@@ -207,6 +207,31 @@ export const getServerSideProps = wrapper.getServerSideProps(
// awaitingSubmissionFromBlob.case
// );
console.log(
"preferred language:",
accountDetails.pinswg_preferredlanguage
);
console.log(
"locale :",
accountDetails.pinswg_preferredlanguage == "846040000" ? "cy" : "en"
);
console.log("req locale :", ctx.locale);
const preferredLocale =
accountDetails.pinswg_preferredlanguage == "846040000"
? "cy"
: "en";
// if (preferredLocale != ctx.locale) {
// return {
// redirect: {
// destination: "/cy/myportal",
// permanent: false,
// },
// };
// } else {
if (_.has(accountDetails, "errorCode") != false) {
return {
redirect: {
@@ -255,6 +280,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
},
};
}
// }
}
);
+13
View File
@@ -28,6 +28,8 @@ import {
setLoggedInUserId,
} from "../../store/accountDetails/action";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => {
const { footerLinks, pages } = props;
let { t, lang } = useTranslation();
@@ -62,6 +64,17 @@ const Home = (props) => {
updateAccountStore();
}, [dispatch]);
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+53 -43
View File
@@ -84,51 +84,61 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
let [searchResultsObj, loggedInUser] = await Promise.all([
await getBasicSearch(query.q),
await getPortalLogin(thisSession.user.email),
]);
const showReps = process.env.SHOWREPRESENTATIONS || false;
const showLoginCheck = process.env.SHOWLOGIN || false;
store.dispatch(setShowReps(showReps, showLoginCheck));
console.log("env var ", process.env.SHOWREPRESENTATIONS);
store.dispatch(setShowReps(showReps, showLoginCheck));
searchResultsObj =
searchResultsObj.status == 502
? {
value: [],
errorCode: searchResultsObj.status,
errorMsg: searchResultsObj.statusText,
}
: searchResultsObj;
//console.log("sssss", searchResultsObj);
loggedInUser = loggedInUser.value[0].contactid;
const watchedCases = await getWatchedCases(loggedInUser);
console.log("sssss", loggedInUser);
const [accountDetails, searchDetailsObj, watchedCasesDetails] =
await Promise.all([
await getPersonalAccount(loggedInUser),
await getSearchDetails(searchResultsObj),
await getDetails(watchedCases, "myWatchedCases"),
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
let [searchResultsObj, loggedInUser] = await Promise.all([
await getBasicSearch(query.q),
await getPortalLogin(thisSession.user.email),
]);
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
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));
const showReps = process.env.SHOWREPRESENTATIONS || false;
const showLoginCheck = process.env.SHOWLOGIN || false;
store.dispatch(setShowReps(showReps, showLoginCheck));
console.log("env var ", process.env.SHOWREPRESENTATIONS);
store.dispatch(setShowReps(showReps, showLoginCheck));
searchResultsObj =
searchResultsObj.status == 502
? {
value: [],
errorCode: searchResultsObj.status,
errorMsg: searchResultsObj.statusText,
}
: searchResultsObj;
//console.log("sssss", searchResultsObj);
loggedInUser = loggedInUser.value[0].contactid;
const watchedCases = await getWatchedCases(loggedInUser);
console.log("sssss", loggedInUser);
const [accountDetails, searchDetailsObj, watchedCasesDetails] =
await Promise.all([
await getPersonalAccount(loggedInUser),
await getSearchDetails(searchResultsObj),
await getDetails(watchedCases, "myWatchedCases"),
]);
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
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));
}
}
);
+12
View File
@@ -8,6 +8,7 @@ import Footer from "../../components/footer";
import Header from "../../components/header";
import ViewAll from "../../components/myportal/viewall";
import TimeOut from "../../components/timeout";
import { getSession, useSession } from "next-auth/react";
const Home = (props) => {
const { footerLinks, pages } = props;
@@ -17,6 +18,17 @@ const Home = (props) => {
const { locale } = router;
const { appealtypes } = router.query;
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>