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
+55
View File
@@ -0,0 +1,55 @@
import Head from "next/head";
import Header from "../components/header";
import Banner from "../components/banner";
import CookieBanner from "../components/cookieBanner";
import Breadcrumbs from "../components/breadcrumbs";
import Footer from "../components/footer";
import useTranslation from "next-translate/useTranslation";
const NoSessionWarning = (props) => {
const { footerLinks, loading } = props;
let { t, lang } = useTranslation();
return (
<div>
<Head>
<title>
{t("search:page-title")} - {t("common:service-name")}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header courseName={t("common:service-name")} />
<div className="govuk-grid-row">
<div className="govuk-grid-column-full">
<div className="govuk-width-container">
<main
className="govuk-main-wrapper--auto-spacing"
id="main-content"
role="main"
>
<div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds">
<h1>
{
(loading = !true
? "Loading"
: "You are not logged in")
}{" "}
</h1>
</div>
</div>
</main>
</div>
</div>
</div>
<Footer footerLinks={footerLinks} />
</div>
</div>
);
};
export default NoSessionWarning;
+14
View File
@@ -28,6 +28,9 @@ import {
import { getAppealsTypes, getLPA } from "../../actions";
import { setLPA } from "../../store/lpa/action";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => {
const { footerLinks, pages, formData } = props;
let { t, lang } = useTranslation();
@@ -39,6 +42,17 @@ const Home = (props) => {
const { appealType, LPAData } = props;
const [passwordUpdated, setPasswordUpdated] = useState(false);
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+14 -1
View File
@@ -17,9 +17,11 @@ import jsonpath from "jsonpath";
import { reduxForm, formValueSelector } from "redux-form";
import RegisterForm from "../../components/account/registerform";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => {
const { footerLinks, formData } = props;
const { footerLinks } = props;
let { t, lang } = useTranslation();
const router = useRouter();
@@ -29,6 +31,17 @@ const Home = (props) => {
const [registerFormComplete, setRegisterFormComplete] = useState(false);
const [accountCreatedComplete, setAccountCreatedComplete] = useState(false);
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+13 -1
View File
@@ -15,7 +15,8 @@ import { useState } from "react";
import useTranslation from "next-translate/useTranslation";
import jsonpath from "jsonpath";
import { reduxForm, formValueSelector } from "redux-form";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
import RegisterForm from "../../components/account/registerform";
const Home = (props) => {
@@ -29,6 +30,17 @@ const Home = (props) => {
const [registerFormComplete, setRegisterFormComplete] = useState(false);
const [accountCreatedComplete, setAccountCreatedComplete] = useState(false);
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+13
View File
@@ -20,6 +20,8 @@ import PersonalDetails from "../../components/account/personaldetails";
import { setAccountDetails } from "../../store/accountDetails/action";
import { getPersonalAccount } from "../../actions";
import { setCookie } from "nookies";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => {
const { footerLinks, formData } = props;
@@ -36,6 +38,17 @@ const Home = (props) => {
setCookie(null, "pinsUser", props.accountDetails.loggedinUserId),
{ path: "/" };
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return (
<div>
<Head>
+15 -5
View File
@@ -162,11 +162,21 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
console.log(
"auth sess for register :",
thisSession,
thisSession.user.email
);
// console.log(
// "auth sess for register :",
// thisSession,
// thisSession.user.email
// );
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
}
return {
props: {
+3
View File
@@ -0,0 +1,3 @@
export { default } from "next-auth/middleware";
export const config = { matcher: ["/myportal/:path*"] };
+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>
+10
View File
@@ -225,6 +225,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;
+14
View File
@@ -9,6 +9,7 @@ import Header from "../../components/header";
import Aboutyou from "../../components/newappeal/aboutyou";
import CreateCase from "../../components/newappeal/createCase";
import { wrapper } from "../../store/store";
import { getSession, useSession } from "next-auth/react";
const AboutYou = (props) => {
const { footerLinks, pages, formData } = props;
@@ -118,6 +119,19 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log(cookies);
let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
}
}
);
+40 -27
View File
@@ -141,39 +141,52 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession);
if (_.has(thisSession, "user") == false) {
// if (_.has(thisSession, "user") == false) {
// return {
// redirect: {
// destination: "/error",
// permanent: false,
// },
// };
// }
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/error",
destination: "/auth/signin",
permanent: false,
},
};
} else {
let loggedInUserIdent = thisSession.user.id;
let loggedInUser = cookies.pinsUser;
console.log("has loggedInUser", loggedInUser);
const [appealTypeData, lpaData, accountDetails] = await Promise.all(
[
await getAppealsTypesForNewAppeal(),
await getLPA(),
await getPersonalAccount(loggedInUser),
]
);
console.log("wewerwe s s", accountDetails);
// const lpaData = require("../../data/lpa.json");
// const appealTypeData = require("../../data/appealtypes.json");
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setContainerID(thisSession.user.id));
return {
props: { loggedInUserIdent: loggedInUserIdent },
};
}
let loggedInUserIdent = thisSession.user.id;
let loggedInUser = cookies.pinsUser;
console.log("has loggedInUser", loggedInUser);
const [appealTypeData, lpaData, accountDetails] = await Promise.all([
await getAppealsTypesForNewAppeal(),
await getLPA(),
await getPersonalAccount(loggedInUser),
]);
console.log("wewerwe s s", accountDetails);
// const lpaData = require("../../data/lpa.json");
// const appealTypeData = require("../../data/appealtypes.json");
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setLPA(lpaData));
store.dispatch(setLoggedInUserId(loggedInUser));
store.dispatch(setAccountDetails(accountDetails));
store.dispatch(setContainerID(thisSession.user.id));
return {
props: { loggedInUserIdent: loggedInUserIdent },
};
}
);