Merged PR 2188: mocku pand welsh login flow
Related work items: #22079, #22081
This commit is contained in:
@@ -37,7 +37,7 @@ const RenderTextfield = ({
|
||||
htmlFor={id}
|
||||
id={id + "_label"}
|
||||
>
|
||||
<span className="govuk-body-s">{hint1}</span>
|
||||
<p className="govuk-body-s">{hint1}</p>
|
||||
</label>
|
||||
<ul className="govuk-body-s govuk-!-margin-top-3">
|
||||
<li>{hint2} </li>
|
||||
@@ -90,7 +90,7 @@ let CaseSearch = (props) => {
|
||||
|
||||
throw new SubmissionError({
|
||||
basicSearch: t("home:casesearch-search-validation-required"),
|
||||
_error: "required",
|
||||
_error: "required"
|
||||
});
|
||||
} else {
|
||||
router.push({
|
||||
@@ -98,7 +98,7 @@ let CaseSearch = (props) => {
|
||||
router.locale == "cy"
|
||||
? "/canlyniadauchwilio"
|
||||
: "/searchresults",
|
||||
query: { q: values.basicSearch },
|
||||
query: { q: values.basicSearch }
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -111,14 +111,16 @@ let CaseSearch = (props) => {
|
||||
<h2 className="heading-small card-heading">
|
||||
{t("home:casesearch-card-title")}
|
||||
</h2>
|
||||
|
||||
<p className="govuk-body-s">
|
||||
{t("home:casesearch-card-paragraph")}
|
||||
</p>
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"home:casesearch-search-validation-minlength"
|
||||
)
|
||||
),
|
||||
)
|
||||
]}
|
||||
className="govuk-input"
|
||||
component={RenderTextfield}
|
||||
@@ -144,7 +146,7 @@ let CaseSearch = (props) => {
|
||||
"event",
|
||||
"SearchButtonClicked",
|
||||
{
|
||||
searchTerm: basicSearch.value,
|
||||
searchTerm: basicSearch.value
|
||||
}
|
||||
);
|
||||
}}
|
||||
@@ -193,7 +195,7 @@ const mapStateToProps = (state) => {
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
awaitingSubmission: state.awaitingSubmission
|
||||
};
|
||||
};
|
||||
|
||||
@@ -207,6 +209,6 @@ export default connect(
|
||||
)(
|
||||
reduxForm({
|
||||
form: "basicSearchForm",
|
||||
destroyOnUnmount: false,
|
||||
destroyOnUnmount: false
|
||||
})(CaseSearch)
|
||||
);
|
||||
|
||||
@@ -27,14 +27,14 @@ const MyPortal = (props) => {
|
||||
|
||||
const handleLogout = () => {
|
||||
console.info("////////////\n" + "logout" + "\n////////////");
|
||||
window.localStorage.clear(),
|
||||
(window.localStorage.clear(),
|
||||
destroyCookie(null, "next-auth.csrf-token", { path: "/" }),
|
||||
destroyCookie(null, "next-auth.callback-url", { path: "/" }),
|
||||
destroyCookie(null, "pedw_locale", { path: "/" }),
|
||||
destroyCookie(null, "pinsUser", { path: "/" }),
|
||||
signOut({
|
||||
callbackUrl: locale == "cy" ? "/cy/allgofnodi" : "/logout",
|
||||
});
|
||||
callbackUrl: locale == "cy" ? "/cy/allgofnodi" : "/logout"
|
||||
}));
|
||||
};
|
||||
|
||||
const isLPA =
|
||||
@@ -114,7 +114,7 @@ const MyPortal = (props) => {
|
||||
] +
|
||||
'")].value_cy',
|
||||
json: transLookup,
|
||||
eval: true,
|
||||
eval: true
|
||||
})
|
||||
: props.accountDetails.accountDetails[
|
||||
"pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue"
|
||||
@@ -126,10 +126,11 @@ const MyPortal = (props) => {
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<div className="flex-container grid-row govuk-body ">
|
||||
<SearchCases />
|
||||
{!isLPA && (
|
||||
<MakeNewAppeal docsOffline={docsOffline} />
|
||||
)}
|
||||
<SearchCases />
|
||||
|
||||
{/* {props.awaitingSubmission.awaitingSubmission[
|
||||
"@odata.count"
|
||||
] > 0 && (
|
||||
@@ -143,7 +144,7 @@ const MyPortal = (props) => {
|
||||
{!isLPA &&
|
||||
_.has(props.awaitingSubmission, [
|
||||
"awaitingSubmissionFromBlob",
|
||||
"@odata.count",
|
||||
"@odata.count"
|
||||
]) &&
|
||||
props.awaitingSubmission
|
||||
.awaitingSubmissionFromBlob[
|
||||
|
||||
@@ -88,7 +88,7 @@ let AdvancedSearch = (props) => {
|
||||
optionsObj,
|
||||
meta: { touched, error },
|
||||
label,
|
||||
errormsg,
|
||||
errormsg
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
@@ -143,7 +143,7 @@ let AdvancedSearch = (props) => {
|
||||
.name +
|
||||
'")].value_cy',
|
||||
json: transLookup,
|
||||
eval: true,
|
||||
eval: true
|
||||
})
|
||||
: optionsObj[key].name ||
|
||||
t(
|
||||
@@ -166,7 +166,7 @@ let AdvancedSearch = (props) => {
|
||||
optionsObj,
|
||||
meta: { touched, error },
|
||||
label,
|
||||
errormsg,
|
||||
errormsg
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
@@ -213,47 +213,52 @@ let AdvancedSearch = (props) => {
|
||||
_.isEmpty(optionsObj[key])
|
||||
? ""
|
||||
: _.isEmpty(
|
||||
optionsObj[key]
|
||||
)
|
||||
? ""
|
||||
: _.isEmpty(
|
||||
optionsObj[key]
|
||||
.value
|
||||
)
|
||||
? ""
|
||||
: optionsObj[key]
|
||||
.attributevalue +
|
||||
"," +
|
||||
optionsObj[key].value
|
||||
.replace(
|
||||
/(\band|[\s\-\+\(\)\,\&])/g,
|
||||
""
|
||||
optionsObj[key]
|
||||
)
|
||||
? ""
|
||||
: _.isEmpty(
|
||||
optionsObj[key]
|
||||
.value
|
||||
)
|
||||
.toLowerCase()
|
||||
? ""
|
||||
: optionsObj[key]
|
||||
.attributevalue +
|
||||
"," +
|
||||
optionsObj[
|
||||
key
|
||||
].value
|
||||
.replace(
|
||||
/(\band|[\s\-\+\(\)\,\&])/g,
|
||||
""
|
||||
)
|
||||
.toLowerCase()
|
||||
}
|
||||
>
|
||||
{_.isEmpty(optionsObj[key])
|
||||
? ""
|
||||
: _.isEmpty(optionsObj[key])
|
||||
? ""
|
||||
: _.isEmpty(
|
||||
optionsObj[key].value
|
||||
)
|
||||
? ""
|
||||
: router.locale == "cy"
|
||||
? jsonpath({
|
||||
path:
|
||||
'$..[?(@ && @.value=="' +
|
||||
? ""
|
||||
: _.isEmpty(
|
||||
optionsObj[key]
|
||||
.value +
|
||||
'")].value_cy',
|
||||
json: transLookup,
|
||||
eval: true,
|
||||
})
|
||||
: optionsObj[key].value ||
|
||||
t(
|
||||
"case:summary-no-date-entered-label"
|
||||
)}
|
||||
.value
|
||||
)
|
||||
? ""
|
||||
: router.locale == "cy"
|
||||
? jsonpath({
|
||||
path:
|
||||
'$..[?(@ && @.value=="' +
|
||||
optionsObj[
|
||||
key
|
||||
].value +
|
||||
'")].value_cy',
|
||||
json: transLookup,
|
||||
eval: true
|
||||
})
|
||||
: optionsObj[key]
|
||||
.value ||
|
||||
t(
|
||||
"case:summary-no-date-entered-label"
|
||||
)}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
@@ -325,7 +330,7 @@ let AdvancedSearch = (props) => {
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
)
|
||||
]}
|
||||
className="govuk-input govuk-!-width-two-thirds"
|
||||
component={RenderTextfield}
|
||||
@@ -475,7 +480,7 @@ const mapStateToProps = (state) => {
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
awaitingSubmission: state.awaitingSubmission
|
||||
};
|
||||
};
|
||||
|
||||
@@ -491,6 +496,6 @@ export default connect(
|
||||
)(
|
||||
reduxForm({
|
||||
form: "advancedSearchForm",
|
||||
destroyOnUnmount: false,
|
||||
destroyOnUnmount: false
|
||||
})(AdvancedSearch)
|
||||
);
|
||||
|
||||
@@ -19,6 +19,9 @@ export default function MakeNewAppeal(props) {
|
||||
<h2 className="govuk-heading-s">
|
||||
{t("myportal:makenewappeal-card-title")}
|
||||
</h2>
|
||||
<p className="govuk-body-s">
|
||||
{t("myportal:makenewappeal-card-paragraph-zero")}
|
||||
</p>
|
||||
<p className="govuk-body-s">
|
||||
{t("myportal:makenewappeal-card-paragraph-one")}{" "}
|
||||
<Link href={t("myportal:makenewappeal-card-guidance-link")}>
|
||||
|
||||
@@ -36,7 +36,7 @@ const RenderTextfield = ({
|
||||
htmlFor={id}
|
||||
id={id + "_label"}
|
||||
>
|
||||
<span className="govuk-body-s">{hint1}</span>
|
||||
<p className="govuk-body-s">{hint1}</p>
|
||||
</label>
|
||||
<ul className="govuk-body-s govuk-!-margin-top-3">
|
||||
<li>{hint2} </li>
|
||||
@@ -89,7 +89,7 @@ let CaseSearch = (props) => {
|
||||
|
||||
throw new SubmissionError({
|
||||
basicSearch: t("myportal:searchcases-validation-required"),
|
||||
_error: "required",
|
||||
_error: "required"
|
||||
});
|
||||
} else {
|
||||
router.push({
|
||||
@@ -97,7 +97,7 @@ let CaseSearch = (props) => {
|
||||
router.locale == "cy"
|
||||
? "/fymhorth/canlyniadauchwilio"
|
||||
: "/myportal/searchresults",
|
||||
query: { q: values.basicSearch },
|
||||
query: { q: values.basicSearch }
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -111,13 +111,17 @@ let CaseSearch = (props) => {
|
||||
{t("myportal:searchcases-card-title")}
|
||||
</h3>
|
||||
|
||||
<p className="govuk-body-s">
|
||||
{t("myportal:searchcases-card-paragraph")}
|
||||
</p>
|
||||
|
||||
<Field
|
||||
validate={[
|
||||
minLength(
|
||||
t(
|
||||
"myportal:searchcases-validation-minlength"
|
||||
)
|
||||
),
|
||||
)
|
||||
]}
|
||||
className="govuk-input"
|
||||
component={RenderTextfield}
|
||||
@@ -143,7 +147,7 @@ let CaseSearch = (props) => {
|
||||
"event",
|
||||
"MyPortalSearchButtonClicked",
|
||||
{
|
||||
searchTerm: basicSearch.value,
|
||||
searchTerm: basicSearch.value
|
||||
}
|
||||
);
|
||||
}}
|
||||
@@ -201,7 +205,7 @@ const mapStateToProps = (state) => {
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
awaitingSubmission: state.awaitingSubmission
|
||||
};
|
||||
};
|
||||
|
||||
@@ -215,6 +219,6 @@ export default connect(
|
||||
)(
|
||||
reduxForm({
|
||||
form: "basicSearchForm",
|
||||
destroyOnUnmount: false,
|
||||
destroyOnUnmount: false
|
||||
})(CaseSearch)
|
||||
);
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
"login-card-forgotten-link": "Cliciwch yma",
|
||||
"login-via-gov-gateway-label": "Mewngofnodwch drwy Borth y Llywodraeth",
|
||||
"login-via-nextuth-label": "Mewngofnodwch gyda'ch cyfeiriad e-bost",
|
||||
"casesearch-card-title": "Chwilio am achos",
|
||||
"casesearch-card-title": "Angen gwybodaeth am apêl neu gais?",
|
||||
"casesearch-card-paragraph": "Mae ein gwybodaeth yn dangos manylion am apêl ac a allwch chi gyflwyno sylwadau yn ei herbyn.",
|
||||
"casesearch-card-search-hint": "Defnyddiwch gyfeirnod yr achos, y prosiect Seilwaith neu gyfeirnod cais yr Awdurdod Cynllunio Lleol i chwilio. Bydd cyfeirnod yr achos yn debyg i un o'r canlynol:",
|
||||
"casesearch-card-search-example-label-1": "APP-A12345-A-21-1234567",
|
||||
"casesearch-card-search-example-label-2": "CAS-12345-A1B2C3",
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"viewall-link-count": "Gweld pob un o'r {{count}} o achosion",
|
||||
"page-title": "Fy Mhorth",
|
||||
"lpa-portal-heading": "Porth LPA",
|
||||
"makenewappeal-card-title": "Gwneud apêl newydd",
|
||||
"makenewappeal-card-title": "A gafodd cais cynllunio ei wrthod?",
|
||||
"makenewappeal-card-paragraph-zero": "Os yw eich cais cynllunio wedi cael ei wrthod gan eich Awdurdod Cynllunio Lleol, gallwch gyflwyno apêl yn erbyn eu penderfyniad.",
|
||||
"makenewappeal-card-paragraph-one": "Cyn cyflwyno apêl newydd, gwnewch yn siŵr eich bod wedi darllen yr holl",
|
||||
"makenewappeal-card-link": "sy'n berthnasol i'r math o apêl sydd gennych.",
|
||||
"makenewappeal-card-paragraph-two": "Unwaith y byddwch wedi dewis y botwm 'Gwneud apêl newydd', cewch eich arwain trwy broses i'ch helpu i ddewis yr apêl gywir.",
|
||||
@@ -15,7 +16,8 @@
|
||||
"makenewappeal-card-guidance-link": "https://www.llyw.cymru/arweiniad-ar-apeliadau-cheisiadau",
|
||||
"makenewappeal-card-button-label": "Gwneud apêl newydd",
|
||||
"mycases-card-title": "Fy achosion",
|
||||
"searchcases-card-title": "Chwilio am achos",
|
||||
"searchcases-card-title": "Angen gwybodaeth am apêl neu gais?",
|
||||
"searchcases-card-paragraph": "Mae ein gwybodaeth yn dangos manylion am apêl ac a allwch chi gyflwyno sylwadau yn ei herbyn.",
|
||||
"searchcases-card-search-hint": "Defnyddiwch gyfeirnod yr achos, y prosiect Seilwaith neu gyfeirnod cais yr Awdurdod Cynllunio Lleol i chwilio. Bydd cyfeirnod yr achos yn debyg i un o'r canlynol:",
|
||||
"searchcases-card-search-example-label-1": "APP-A12345-A-21-1234567",
|
||||
"searchcases-card-search-example-label-2": "CAS-12345-A1B2C3",
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
"login-card-forgotten-link": "Click here",
|
||||
"login-via-gov-gateway-label": "Log in via Government Gateway",
|
||||
"login-via-nextuth-label": "Sign in with your email address",
|
||||
"casesearch-card-title": "Search for a case",
|
||||
"casesearch-card-title": "Need information on an appeal or application?",
|
||||
"casesearch-card-paragraph": "Our information shows details on an appeal and whether you can raise representations against it.",
|
||||
"casesearch-card-search-hint": "Use the case reference, Infrastructure project or Local Planning Authority application reference to search. Case reference will be similar to one of the following:",
|
||||
"casesearch-card-search-example-label-1": "APP-A12345-A-21-1234567",
|
||||
"casesearch-card-search-example-label-2": "CAS-12345-A1B2C3",
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"viewall-link-count": "View all {{count}} cases",
|
||||
"page-title": "My Portal",
|
||||
"lpa-portal-heading": "LPA Portal",
|
||||
"makenewappeal-card-title": "Make a new appeal",
|
||||
"makenewappeal-card-title": "Had a planning application refused?",
|
||||
"makenewappeal-card-paragraph-zero": "If you have had a planning application turned down by your Local Planning Authority, you can submit an appeal against their decision.",
|
||||
"makenewappeal-card-paragraph-one": "Before submitting a new appeal, please ensure you have read all of the",
|
||||
"makenewappeal-card-link": "relevant to your appeal type.",
|
||||
"makenewappeal-card-paragraph-two": "Once you have selected the 'Make a new appeal' button, you will be guided through a process to help you choose the right type of appeal.",
|
||||
@@ -15,7 +16,8 @@
|
||||
"makenewappeal-card-guidance-link": "https://www.gov.wales/planning-appeals-guidance",
|
||||
"makenewappeal-card-button-label": "Make a new appeal",
|
||||
"mycases-card-title": "My cases",
|
||||
"searchcases-card-title": "Search for a case",
|
||||
"searchcases-card-title": "Need information on an appeal or application?",
|
||||
"searchcases-card-paragraph": "Our information shows details on an appeal and whether you can raise representations against it.",
|
||||
"searchcases-card-search-hint": "Use the case reference, Infrastructure project or Local Planning Authority application reference to search. Case reference will be similar to one of the following:",
|
||||
"searchcases-card-search-example-label-1": "APP-A12345-A-21-1234567",
|
||||
"searchcases-card-search-example-label-2": "CAS-12345-A1B2C3",
|
||||
|
||||
+50
-130
@@ -15,67 +15,34 @@ import { PrismaClient } from "@prisma/client";
|
||||
import NextAuth from "next-auth";
|
||||
import EmailProvider from "next-auth/providers/email";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getPreferredLanguage } from "../../../actions/services/accountService";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const parseUrl = (url) => {
|
||||
const defaultUrl = new URL(
|
||||
$(
|
||||
(locale == "cy"
|
||||
? process.env.CY_API_ROOT
|
||||
: process.env.NEXTAUTH_URL) + `/api/auth`
|
||||
)
|
||||
);
|
||||
|
||||
if (url && !url.startsWith("http")) {
|
||||
url = `https://${url}`;
|
||||
}
|
||||
|
||||
const _url = new URL(url ?? defaultUrl);
|
||||
const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname)
|
||||
// Remove trailing slash
|
||||
.replace(/\/$/, "");
|
||||
|
||||
const base = `${_url.origin}${path}`;
|
||||
|
||||
return {
|
||||
origin: _url.origin,
|
||||
host: _url.host,
|
||||
path,
|
||||
base,
|
||||
toString: () => base
|
||||
};
|
||||
};
|
||||
|
||||
const appendParamsAndPathToNewUrl = (fromUrl, toUrl) => {
|
||||
const fromUrlObj = new URL(fromUrl); // Parse the source URL
|
||||
const params = fromUrlObj.searchParams; // Extract the query parameters
|
||||
const fromUrlObj = new URL(fromUrl);
|
||||
const params = fromUrlObj.searchParams;
|
||||
|
||||
const toUrlObj = new URL(toUrl); // Parse the new domain URL
|
||||
toUrlObj.pathname = fromUrlObj.pathname; // Copy the path from the source URL
|
||||
const toUrlObj = new URL(toUrl);
|
||||
toUrlObj.pathname = fromUrlObj.pathname;
|
||||
|
||||
// Append only the parameters that don't already exist in the destination URL
|
||||
params.forEach((value, key) => {
|
||||
if (!toUrlObj.searchParams.has(key)) {
|
||||
// Check if the parameter already exists
|
||||
toUrlObj.searchParams.append(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
return toUrlObj.toString(); // Return the full new URL as a string
|
||||
return toUrlObj.toString();
|
||||
};
|
||||
|
||||
const authOptions = (locale, req, res) => {
|
||||
//console.log(req.query.callbackUrl);
|
||||
// let newURL = parseUrl(
|
||||
// locale == "cy"
|
||||
// ? "https://" + process.env.I18N_DOMAIN + ":3000"
|
||||
// : process.env.NEXTAUTH_URL
|
||||
// );
|
||||
// console.log("which locale", locale);
|
||||
// console.log("which referer", req.body);
|
||||
// console.log("cookie locale", req.cookies["pedw_locale"]);
|
||||
const resolveLocale = (req) =>
|
||||
req?.query?.locale ||
|
||||
req?.body?.locale ||
|
||||
req?.cookies?.pedw_locale ||
|
||||
"en";
|
||||
|
||||
const authOptions = (req, res) => {
|
||||
const locale = resolveLocale(req);
|
||||
|
||||
return {
|
||||
providers: [
|
||||
{
|
||||
@@ -83,29 +50,19 @@ const authOptions = (locale, req, res) => {
|
||||
name: "emailAPI",
|
||||
type: "email",
|
||||
async sendVerificationRequest({ identifier: email, url }) {
|
||||
const { host, port, protocol, token, searchParams } =
|
||||
new URL(url);
|
||||
const { host, protocol, searchParams } = new URL(url);
|
||||
|
||||
console.log(
|
||||
"============================================================\n",
|
||||
"verification url API: " + url + "\n",
|
||||
"============================================================\n"
|
||||
);
|
||||
|
||||
const baseDomain = `${protocol}//${host}`;
|
||||
const emailAddress = email;
|
||||
const prefLang = await getPreferredLanguage(emailAddress);
|
||||
const effectiveLocale = resolveLocale(req);
|
||||
|
||||
const registeredPrefLanguage =
|
||||
prefLang.value.length > 0
|
||||
? prefLang.value[0].pinswg_preferredlanguage ===
|
||||
846040000
|
||||
? "cy"
|
||||
: "en"
|
||||
: "en";
|
||||
|
||||
const effectiveLocale = registeredPrefLanguage ?? locale;
|
||||
|
||||
let newURL =
|
||||
effectiveLocale == "cy"
|
||||
const newURL =
|
||||
effectiveLocale === "cy"
|
||||
? baseDomain +
|
||||
"/api/auth/callback/email?callbackUrl=" +
|
||||
encodeURIComponent(baseDomain + "/cy") +
|
||||
@@ -117,7 +74,7 @@ const authOptions = (locale, req, res) => {
|
||||
effectiveLocale
|
||||
: url;
|
||||
|
||||
let formURL = appendParamsAndPathToNewUrl(url, newURL);
|
||||
const formURL = appendParamsAndPathToNewUrl(url, newURL);
|
||||
|
||||
console.log(
|
||||
"============================================================\n",
|
||||
@@ -131,19 +88,14 @@ const authOptions = (locale, req, res) => {
|
||||
}
|
||||
},
|
||||
EmailProvider({
|
||||
maxAge: 2 * 60 * 60, //10 * 60, // Magic links are valid for 10 min only
|
||||
maxAge: 2 * 60 * 60,
|
||||
async sendVerificationRequest({ identifier: email, url }) {
|
||||
const { host, port, protocol, token, searchParams } =
|
||||
new URL(url);
|
||||
const { host, protocol, searchParams } = new URL(url);
|
||||
|
||||
const baseDomain = `${protocol}//${host}`;
|
||||
const templateId = "b1b5704b-9bb8-4deb-a75c-d887ca902661";
|
||||
const templateIdcy = "0614ce53-cd5f-421f-a1a5-8c8486a9113a";
|
||||
const emailAddress = email;
|
||||
|
||||
const queryLocale = req?.query?.locale || req?.body?.locale;
|
||||
const cookieLocale = req.cookies["pedw_locale"];
|
||||
let locale = queryLocale || cookieLocale || "en";
|
||||
const effectiveLocale = resolveLocale(req);
|
||||
|
||||
console.log(
|
||||
"============================================================\n",
|
||||
@@ -151,19 +103,8 @@ const authOptions = (locale, req, res) => {
|
||||
"============================================================\n"
|
||||
);
|
||||
|
||||
const prefLang = await getPreferredLanguage(emailAddress);
|
||||
|
||||
const registeredPrefLanguage =
|
||||
prefLang.value.length > 0
|
||||
? prefLang.value[0].pinswg_preferredlanguage ===
|
||||
846040000
|
||||
? "cy"
|
||||
: "en"
|
||||
: "en";
|
||||
|
||||
const effectiveLocale = registeredPrefLanguage ?? locale;
|
||||
let newURL =
|
||||
effectiveLocale == "cy"
|
||||
const newURL =
|
||||
effectiveLocale === "cy"
|
||||
? baseDomain +
|
||||
"/api/auth/callback/email?callbackUrl=" +
|
||||
encodeURIComponent(baseDomain + "/cy") +
|
||||
@@ -175,7 +116,7 @@ const authOptions = (locale, req, res) => {
|
||||
effectiveLocale
|
||||
: url;
|
||||
|
||||
let formURL = appendParamsAndPathToNewUrl(url, newURL);
|
||||
const formURL = appendParamsAndPathToNewUrl(url, newURL);
|
||||
|
||||
console.log(
|
||||
"============================================================\n",
|
||||
@@ -184,16 +125,11 @@ const authOptions = (locale, req, res) => {
|
||||
);
|
||||
|
||||
const personalisation = {
|
||||
"emailAddress": email,
|
||||
"signInLink": formURL,
|
||||
// locale == "cy"
|
||||
// ? url.split("&token")[0] +
|
||||
// "/cy&token" +
|
||||
// url.split("&token")[1]
|
||||
// : url,
|
||||
|
||||
"linkExpiry": 2 * 60 * 60
|
||||
emailAddress: email,
|
||||
signInLink: formURL,
|
||||
linkExpiry: 2 * 60 * 60
|
||||
};
|
||||
|
||||
const reference = "PEDW-SIGNIN";
|
||||
|
||||
var NotifyClient =
|
||||
@@ -205,15 +141,15 @@ const authOptions = (locale, req, res) => {
|
||||
|
||||
await notifyClient
|
||||
.sendEmail(
|
||||
effectiveLocale == "cy" ? templateIdcy : templateId,
|
||||
emailAddress,
|
||||
effectiveLocale === "cy"
|
||||
? templateIdcy
|
||||
: templateId,
|
||||
email,
|
||||
{
|
||||
personalisation: personalisation,
|
||||
reference: reference
|
||||
// emailReplyToId: emailReplyToId,
|
||||
personalisation,
|
||||
reference
|
||||
}
|
||||
)
|
||||
//.then((response) => console.log(response))
|
||||
.catch((error) => consoleLogger(error));
|
||||
}
|
||||
})
|
||||
@@ -227,7 +163,7 @@ const authOptions = (locale, req, res) => {
|
||||
theme: "dark",
|
||||
debug: true,
|
||||
maxAge: 30 * 60,
|
||||
updateAge: 5 * 60 // 24 hours
|
||||
updateAge: 5 * 60
|
||||
},
|
||||
cookies: {
|
||||
callbackUrl: {
|
||||
@@ -240,11 +176,11 @@ const authOptions = (locale, req, res) => {
|
||||
}
|
||||
},
|
||||
pages: {
|
||||
signIn: (locale == "cy" ? "/cy" : "") + "/auth/signin",
|
||||
error: (locale == "cy" ? "/cy" : "") + "/auth/error", // Error code passed in query string as ?error=
|
||||
signIn: (locale === "cy" ? "/cy" : "") + "/auth/signin",
|
||||
error: (locale === "cy" ? "/cy" : "") + "/auth/error",
|
||||
verifyRequest:
|
||||
(locale == "cy" ? "/cy" : "") + "/auth/verify-request", // (used for check email message)
|
||||
newUser: (locale == "cy" ? "/cy" : "") + "/account/register" // New users will be directed here on first sign in (leave the property out if not of interest)
|
||||
(locale === "cy" ? "/cy" : "") + "/auth/verify-request",
|
||||
newUser: (locale === "cy" ? "/cy" : "") + "/account/register"
|
||||
},
|
||||
callbacks: {
|
||||
session: async (session, user) => {
|
||||
@@ -253,28 +189,19 @@ const authOptions = (locale, req, res) => {
|
||||
},
|
||||
|
||||
redirect({ url, baseUrl }) {
|
||||
//debugger;
|
||||
console.log("baseurl:", url, baseUrl);
|
||||
// Allows relative callback URLs
|
||||
if (url.startsWith("/")) return `${baseUrl}${url}`;
|
||||
// Allows callback URLs on the same origin
|
||||
else if (new URL(url).origin === baseUrl) return url;
|
||||
|
||||
const originalUrl = url;
|
||||
let newUrl =
|
||||
locale == "cy"
|
||||
if (url.startsWith("/")) return `${baseUrl}${url}`;
|
||||
if (new URL(url).origin === baseUrl) return url;
|
||||
|
||||
const effectiveLocale = resolveLocale(req);
|
||||
const newUrl =
|
||||
effectiveLocale === "cy"
|
||||
? process.env.CY_API_ROOT
|
||||
: process.env.NEXTAUTH_URL;
|
||||
|
||||
const updatedUrl = appendParamsAndPathToNewUrl(
|
||||
originalUrl,
|
||||
newUrl
|
||||
);
|
||||
const updatedUrl = appendParamsAndPathToNewUrl(url, newUrl);
|
||||
console.log(updatedUrl);
|
||||
|
||||
//return baseUrl;
|
||||
|
||||
console.log("the url:", updatedUrl);
|
||||
return updatedUrl;
|
||||
}
|
||||
}
|
||||
@@ -282,14 +209,7 @@ const authOptions = (locale, req, res) => {
|
||||
};
|
||||
|
||||
const NextAuthPEDW = (req, res) => {
|
||||
//console.log("----------", authOptions(req.cookies["pedw_locale"]));
|
||||
|
||||
//console.log("----------",
|
||||
return NextAuth(
|
||||
req,
|
||||
res,
|
||||
authOptions(req.cookies["pedw_locale"], req, res)
|
||||
);
|
||||
return NextAuth(req, res, authOptions(req, res));
|
||||
};
|
||||
|
||||
export default NextAuthPEDW;
|
||||
|
||||
+20
-72
@@ -7,55 +7,28 @@ import CookieBanner from "../../components/cookieBanner";
|
||||
import Footer from "../../components/footer";
|
||||
import Header from "../../components/header";
|
||||
import ServiceBanner from "../../components/servicebanner";
|
||||
import { getPreferredLanguage } from "../../actions/services/accountService";
|
||||
import { setCookie } from "nookies";
|
||||
|
||||
const SignIn = (props) => {
|
||||
let { t, lang } = useTranslation();
|
||||
const { footerLinks, pages, csrfToken, callbackUrl } = props;
|
||||
|
||||
let formURL =
|
||||
new URL(window.location.href).protocol +
|
||||
"//" +
|
||||
new URL(window.location.href).hostname +
|
||||
":" +
|
||||
new URL(window.location.href).port +
|
||||
"/api/auth/signin/email";
|
||||
|
||||
const [buttonDisabled, setButtonDisabled] = useState(false);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
setButtonDisabled(true);
|
||||
|
||||
const email = event.target.email.value;
|
||||
const currentLocale = lang || "en";
|
||||
const url = new URL(event.target.callbackUrl.value);
|
||||
url.searchParams.set("locale", currentLocale);
|
||||
|
||||
try {
|
||||
const res = await getPreferredLanguage(encodeURIComponent(email));
|
||||
const data = await res;
|
||||
setCookie(null, "pedw_locale", currentLocale, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 365
|
||||
});
|
||||
|
||||
const userLang =
|
||||
data.value.length > 0
|
||||
? data.value[0].pinswg_preferredlanguage === 846040000
|
||||
? "cy"
|
||||
: "en"
|
||||
: "en";
|
||||
|
||||
// Modify callbackUrl hidden input to add/update lang param
|
||||
const url = new URL(event.target.callbackUrl.value);
|
||||
url.searchParams.set("locale", userLang);
|
||||
|
||||
setCookie(null, "pedw_locale", userLang, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 365
|
||||
});
|
||||
|
||||
event.target.callbackUrl.value = url.toString();
|
||||
} catch (error) {
|
||||
console.error("Failed to get preferred language", error);
|
||||
}
|
||||
|
||||
// Submit form after updating callbackUrl
|
||||
event.target.callbackUrl.value = url.toString();
|
||||
event.target.submit();
|
||||
};
|
||||
|
||||
@@ -97,11 +70,7 @@ const SignIn = (props) => {
|
||||
action="/api/auth/signin/email"
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
"govuk-form-group "
|
||||
}
|
||||
>
|
||||
<div className="govuk-form-group ">
|
||||
<input
|
||||
className="govuk-input"
|
||||
name="csrfToken"
|
||||
@@ -129,7 +98,7 @@ const SignIn = (props) => {
|
||||
</label>
|
||||
|
||||
<input
|
||||
className="govuk-input govuk-!-width-three-quarters"
|
||||
className="govuk-input govuk-!-width-three-quarters"
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
@@ -175,44 +144,31 @@ export async function getServerSideProps(context) {
|
||||
}
|
||||
|
||||
const csrfToken = await getCsrfToken(context);
|
||||
console.log(
|
||||
"\n//////////////////////\n",
|
||||
"Sign in callbackurl: " + context.query.callbackUrl,
|
||||
context.locale,
|
||||
"\n//////////////////////\n"
|
||||
);
|
||||
let formURL = context.req.headers.host;
|
||||
//console.log("formUrl:", formURL);
|
||||
|
||||
let formURL = context.req.headers.host;
|
||||
formURL = typeof formURL == "undefined" ? null : formURL;
|
||||
|
||||
let protocol = "http";
|
||||
if (context.req.headers["x-forwarded-proto"]) {
|
||||
protocol = context.req.headers["x-forwarded-proto"];
|
||||
}
|
||||
// Otherwise, check if the connection is encrypted (for https)
|
||||
else if (context.req.connection.encrypted) {
|
||||
} else if (context.req.connection.encrypted) {
|
||||
protocol = "https";
|
||||
}
|
||||
|
||||
formURL = protocol + "://" + formURL;
|
||||
|
||||
console.log("Protocol:", protocol);
|
||||
console.log("locale:", context.locale);
|
||||
|
||||
const appendParamsAndPathToNewUrl = (fromUrl, toUrl) => {
|
||||
const fromUrlObj = new URL(fromUrl); // Parse the source URL
|
||||
const params = fromUrlObj.searchParams; // Extract the query parameters
|
||||
const fromUrlObj = new URL(fromUrl);
|
||||
const params = fromUrlObj.searchParams;
|
||||
|
||||
const toUrlObj = new URL(toUrl); // Parse the new domain URL
|
||||
toUrlObj.pathname = fromUrlObj.pathname; // Copy the path from the source URL
|
||||
const toUrlObj = new URL(toUrl);
|
||||
toUrlObj.pathname = fromUrlObj.pathname;
|
||||
|
||||
// Append the query parameters to the new URL
|
||||
params.forEach((value, key) =>
|
||||
toUrlObj.searchParams.append(key, value)
|
||||
);
|
||||
|
||||
return toUrlObj.toString(); // Return the full new URL as a string
|
||||
return toUrlObj.toString();
|
||||
};
|
||||
|
||||
typeof context.query.callbackUrl != "undefined" &&
|
||||
@@ -221,19 +177,11 @@ export async function getServerSideProps(context) {
|
||||
formURL
|
||||
));
|
||||
|
||||
//formURL = appendParamsAndPathToNewUrl(context.query.callbackUrl, formURL);
|
||||
|
||||
const url = new URL(formURL); // base URL
|
||||
|
||||
const params = new URLSearchParams(url.search);
|
||||
params.append("locale", context.locale);
|
||||
|
||||
url.search = params.toString();
|
||||
|
||||
console.log("========== callback: ", url.toString());
|
||||
const url = new URL(formURL);
|
||||
url.searchParams.set("locale", context.locale || "en");
|
||||
|
||||
return {
|
||||
props: { csrfToken: csrfToken, callbackUrl: url.toString() }
|
||||
props: { csrfToken, callbackUrl: url.toString() }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user