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 { getAppealsTypes, getLPA } from "../../actions";
import { setLPA } from "../../store/lpa/action"; import { setLPA } from "../../store/lpa/action";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages, formData } = props; const { footerLinks, pages, formData } = props;
let { t, lang } = useTranslation(); let { t, lang } = useTranslation();
@@ -39,6 +42,17 @@ const Home = (props) => {
const { appealType, LPAData } = props; const { appealType, LPAData } = props;
const [passwordUpdated, setPasswordUpdated] = useState(false); 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 ( return (
<div> <div>
<Head> <Head>
+14 -1
View File
@@ -17,9 +17,11 @@ import jsonpath from "jsonpath";
import { reduxForm, formValueSelector } from "redux-form"; import { reduxForm, formValueSelector } from "redux-form";
import RegisterForm from "../../components/account/registerform"; import RegisterForm from "../../components/account/registerform";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => { const Home = (props) => {
const { footerLinks, formData } = props; const { footerLinks } = props;
let { t, lang } = useTranslation(); let { t, lang } = useTranslation();
const router = useRouter(); const router = useRouter();
@@ -29,6 +31,17 @@ const Home = (props) => {
const [registerFormComplete, setRegisterFormComplete] = useState(false); const [registerFormComplete, setRegisterFormComplete] = useState(false);
const [accountCreatedComplete, setAccountCreatedComplete] = 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 ( return (
<div> <div>
<Head> <Head>
+13 -1
View File
@@ -15,7 +15,8 @@ import { useState } from "react";
import useTranslation from "next-translate/useTranslation"; import useTranslation from "next-translate/useTranslation";
import jsonpath from "jsonpath"; import jsonpath from "jsonpath";
import { reduxForm, formValueSelector } from "redux-form"; import { reduxForm, formValueSelector } from "redux-form";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
import RegisterForm from "../../components/account/registerform"; import RegisterForm from "../../components/account/registerform";
const Home = (props) => { const Home = (props) => {
@@ -29,6 +30,17 @@ const Home = (props) => {
const [registerFormComplete, setRegisterFormComplete] = useState(false); const [registerFormComplete, setRegisterFormComplete] = useState(false);
const [accountCreatedComplete, setAccountCreatedComplete] = 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 ( return (
<div> <div>
<Head> <Head>
+13
View File
@@ -20,6 +20,8 @@ import PersonalDetails from "../../components/account/personaldetails";
import { setAccountDetails } from "../../store/accountDetails/action"; import { setAccountDetails } from "../../store/accountDetails/action";
import { getPersonalAccount } from "../../actions"; import { getPersonalAccount } from "../../actions";
import { setCookie } from "nookies"; import { setCookie } from "nookies";
import { getSession, useSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => { const Home = (props) => {
const { footerLinks, formData } = props; const { footerLinks, formData } = props;
@@ -36,6 +38,17 @@ const Home = (props) => {
setCookie(null, "pinsUser", props.accountDetails.loggedinUserId), setCookie(null, "pinsUser", props.accountDetails.loggedinUserId),
{ path: "/" }; { path: "/" };
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return ( return (
<div> <div>
<Head> <Head>
+15 -5
View File
@@ -162,11 +162,21 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
console.log( // console.log(
"auth sess for register :", // "auth sess for register :",
thisSession, // thisSession,
thisSession.user.email // thisSession.user.email
); // );
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
}
return { return {
props: { 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); let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession); //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 loggedInUserIdent = thisSession.user.id;
let loggedInUserEmail = thisSession.user.email; let loggedInUserEmail = thisSession.user.email;
+14 -2
View File
@@ -75,11 +75,22 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
const [accountDetails, appealTypeData, lpaData] = await Promise.all([ 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 getPersonalAccount(loggedInUser),
await getAppealsTypes(), await getAppealsTypes(),
await getLPA(), await getLPA(),
]); ]
);
// const lpaData = require("../../data/lpa.json"); // const lpaData = require("../../data/lpa.json");
// const appealTypeData = require("../../data/appealtypes.json"); // const appealTypeData = require("../../data/appealtypes.json");
@@ -92,6 +103,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
thisSession != false && thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id)); store.dispatch(setContainerID(thisSession.user.id));
} }
}
); );
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
+10
View File
@@ -81,6 +81,15 @@ export const getServerSideProps = wrapper.getServerSideProps(
let loggedInUser = cookies.pinsUser; let loggedInUser = cookies.pinsUser;
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
thisSession != false && thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id)); store.dispatch(setContainerID(thisSession.user.id));
@@ -105,6 +114,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setWatchedCasesDetails(watchedCasesDetails)); store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setSearch(Object.entries(query))); store.dispatch(setSearch(Object.entries(query)));
} }
}
); );
const getDetails = (resultsObj, detailsType) => { const getDetails = (resultsObj, detailsType) => {
+13
View File
@@ -8,6 +8,8 @@ import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer"; import Footer from "../../components/footer";
import Header from "../../components/header"; import Header from "../../components/header";
import TimeOut from "../../components/timeout"; import TimeOut from "../../components/timeout";
import { useSession, getSession } from "next-auth/react";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages, showRepresentations } = props; const { footerLinks, pages, showRepresentations } = props;
@@ -17,6 +19,17 @@ const Home = (props) => {
const { locale } = router; const { locale } = router;
const { appealtypes } = router.query; 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 ( return (
<div> <div>
<Head> <Head>
+16 -2
View File
@@ -30,6 +30,8 @@ import {
setWatchedCasesDetails, setWatchedCasesDetails,
} from "../../store/watchedCases/action"; } from "../../store/watchedCases/action";
import { getSession, useSession } from "next-auth/react";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages, watchedCases, showMap } = props; const { footerLinks, pages, watchedCases, showMap } = props;
let { t, lang } = useTranslation(); let { t, lang } = useTranslation();
@@ -126,8 +128,8 @@ const Home = (props) => {
}; };
export const getServerSideProps = wrapper.getServerSideProps( export const getServerSideProps = wrapper.getServerSideProps(
(store) => (store) => async (ctx) => {
async ({ query, req, res }) => { const { query, req, res } = ctx;
console.log("query-", query); console.log("query-", query);
const { cookies } = req; const { cookies } = req;
@@ -139,6 +141,17 @@ export const getServerSideProps = wrapper.getServerSideProps(
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([ let [searchResultsObj, watchedCases] = await Promise.all([
await getBasicDNSSearch(), await getBasicDNSSearch(),
await getWatchedCases(loggedInUser), await getWatchedCases(loggedInUser),
@@ -170,6 +183,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
props: { showMap: showMapCheck }, props: { showMap: showMapCheck },
}; };
} }
}
); );
const getDetails = (resultsObj, detailsType) => { const getDetails = (resultsObj, detailsType) => {
+12
View File
@@ -7,6 +7,7 @@ import Case from "../../components/case";
import CookieBanner from "../../components/cookieBanner"; import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer"; import Footer from "../../components/footer";
import Header from "../../components/header"; import Header from "../../components/header";
import { useSession, getSession } from "next-auth/react";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages } = props; const { footerLinks, pages } = props;
@@ -16,6 +17,17 @@ const Home = (props) => {
const { locale } = router; const { locale } = router;
const { appealtypes } = router.query; 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 ( return (
<div> <div>
<Head> <Head>
+26
View File
@@ -207,6 +207,31 @@ export const getServerSideProps = wrapper.getServerSideProps(
// awaitingSubmissionFromBlob.case // 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) { if (_.has(accountDetails, "errorCode") != false) {
return { return {
redirect: { redirect: {
@@ -255,6 +280,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
}, },
}; };
} }
// }
} }
); );
+13
View File
@@ -28,6 +28,8 @@ import {
setLoggedInUserId, setLoggedInUserId,
} from "../../store/accountDetails/action"; } from "../../store/accountDetails/action";
import NoSessionWarning from "../../components/nosession";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages } = props; const { footerLinks, pages } = props;
let { t, lang } = useTranslation(); let { t, lang } = useTranslation();
@@ -62,6 +64,17 @@ const Home = (props) => {
updateAccountStore(); updateAccountStore();
}, [dispatch]); }, [dispatch]);
const { data: session, status } = useSession();
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
return ( return (
<div> <div>
<Head> <Head>
+10
View File
@@ -84,6 +84,15 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
if (!thisSession) {
console.log("not has sesssion.......");
return {
redirect: {
destination: "/auth/signin",
permanent: false,
},
};
} else {
let [searchResultsObj, loggedInUser] = await Promise.all([ let [searchResultsObj, loggedInUser] = await Promise.all([
await getBasicSearch(query.q), await getBasicSearch(query.q),
await getPortalLogin(thisSession.user.email), await getPortalLogin(thisSession.user.email),
@@ -130,6 +139,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
thisSession != false && thisSession != false &&
store.dispatch(setContainerID(thisSession.user.id)); store.dispatch(setContainerID(thisSession.user.id));
} }
}
); );
const getDetails = (resultsObj, detailsType) => { const getDetails = (resultsObj, detailsType) => {
+12
View File
@@ -8,6 +8,7 @@ import Footer from "../../components/footer";
import Header from "../../components/header"; import Header from "../../components/header";
import ViewAll from "../../components/myportal/viewall"; import ViewAll from "../../components/myportal/viewall";
import TimeOut from "../../components/timeout"; import TimeOut from "../../components/timeout";
import { getSession, useSession } from "next-auth/react";
const Home = (props) => { const Home = (props) => {
const { footerLinks, pages } = props; const { footerLinks, pages } = props;
@@ -17,6 +18,17 @@ const Home = (props) => {
const { locale } = router; const { locale } = router;
const { appealtypes } = router.query; 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 ( return (
<div> <div>
<Head> <Head>
+10
View File
@@ -225,6 +225,16 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession); //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 loggedInUserIdent = thisSession.user.id;
let loggedInUserEmail = thisSession.user.email; let loggedInUserEmail = thisSession.user.email;
+14
View File
@@ -9,6 +9,7 @@ import Header from "../../components/header";
import Aboutyou from "../../components/newappeal/aboutyou"; import Aboutyou from "../../components/newappeal/aboutyou";
import CreateCase from "../../components/newappeal/createCase"; import CreateCase from "../../components/newappeal/createCase";
import { wrapper } from "../../store/store"; import { wrapper } from "../../store/store";
import { getSession, useSession } from "next-auth/react";
const AboutYou = (props) => { const AboutYou = (props) => {
const { footerLinks, pages, formData } = props; const { footerLinks, pages, formData } = props;
@@ -118,6 +119,19 @@ export const getServerSideProps = wrapper.getServerSideProps(
console.log(cookies); console.log(cookies);
let loggedInUser = cookies.pinsUser; 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,
},
};
}
} }
); );
+18 -5
View File
@@ -141,24 +141,36 @@ export const getServerSideProps = wrapper.getServerSideProps(
let thisSession = await getSession(ctx); let thisSession = await getSession(ctx);
//console.log("nextAuth Session:", thisSession); //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 { return {
redirect: { redirect: {
destination: "/error", destination: "/auth/signin",
permanent: false, permanent: false,
}, },
}; };
} } else {
let loggedInUserIdent = thisSession.user.id; let loggedInUserIdent = thisSession.user.id;
let loggedInUser = cookies.pinsUser; let loggedInUser = cookies.pinsUser;
console.log("has loggedInUser", loggedInUser); console.log("has loggedInUser", loggedInUser);
const [appealTypeData, lpaData, accountDetails] = await Promise.all([ const [appealTypeData, lpaData, accountDetails] = await Promise.all(
[
await getAppealsTypesForNewAppeal(), await getAppealsTypesForNewAppeal(),
await getLPA(), await getLPA(),
await getPersonalAccount(loggedInUser), await getPersonalAccount(loggedInUser),
]); ]
);
console.log("wewerwe s s", accountDetails); console.log("wewerwe s s", accountDetails);
@@ -175,6 +187,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
props: { loggedInUserIdent: loggedInUserIdent }, props: { loggedInUserIdent: loggedInUserIdent },
}; };
} }
}
); );
const mapStateToProps = (state) => { const mapStateToProps = (state) => {