Merged PR 2244: added condition to fix log in journey in welsh if no account in crm

added condition to fix log in journey in welsh if no account in crm

Related work items: #22081, #22303
This commit is contained in:
Robert Bond
2026-04-13 15:54:51 +00:00
parent 0de9268255
commit 15c35d201e
4 changed files with 30 additions and 14 deletions
+5 -5
View File
@@ -24,9 +24,9 @@ class MyDocument extends Document {
const cookieObj = ctx.req.cookies.CookiePolicy || {};
//console.log("useGATracking: ", useGATracking);
setCookie(ctx, "pedw_locale", ctx.locale, {
path: "/",
});
// setCookie(ctx, "pedw_locale", ctx.locale, {
// path: "/",
// });
const headers = ctx.req?.headers;
const generatedNonce = headers?.["x-nonce"];
@@ -84,7 +84,7 @@ class MyDocument extends Document {
__html:
"window.switchDomain = '" +
process.env.I18N_DOMAIN +
"'",
"'"
}}
/>
<script
@@ -93,7 +93,7 @@ class MyDocument extends Document {
__html:
"window.apiRoot = '" +
process.env.API_ROOT +
"'",
"'"
}}
/>
</>
+6 -5
View File
@@ -37,11 +37,12 @@ const appendParamsAndPathToNewUrl = (fromUrl, toUrl) => {
return toUrlObj.toString();
};
const resolveRequestLocale = (req) =>
req?.query?.locale ||
req?.body?.locale ||
req?.cookies?.pedw_locale ||
"en";
const resolveRequestLocale = (req) => {
const locale =
req?.body?.locale || req?.query?.locale || req?.cookies?.pedw_locale;
return locale === "cy" ? "cy" : "en";
};
const resolveCrmLocale = async (email) => {
if (!email) return null;
+14 -2
View File
@@ -21,7 +21,7 @@ const SignIn = (props) => {
try {
const email = String(event.target.email.value || "").trim();
const currentLocale = lang || "en";
const currentLocale = lang === "cy" ? "cy" : "en";
const response = await fetch("/api/auth/resolve-locale", {
method: "POST",
@@ -48,9 +48,10 @@ const SignIn = (props) => {
});
event.target.callbackUrl.value = url.toString();
event.target.locale.value = resolvedLocale;
event.target.submit();
} catch (error) {
const fallbackLocale = lang || "en";
const fallbackLocale = lang === "cy" ? "cy" : "en";
const url = new URL(event.target.callbackUrl.value);
url.searchParams.set("locale", fallbackLocale);
@@ -59,6 +60,7 @@ const SignIn = (props) => {
});
event.target.callbackUrl.value = url.toString();
event.target.locale.value = fallbackLocale;
event.target.submit();
}
};
@@ -118,6 +120,16 @@ const SignIn = (props) => {
callbackUrl
}
/>
<input
name="locale"
type="hidden"
defaultValue={
lang ===
"cy"
? "cy"
: "en"
}
/>
<label
className="govuk-label"
+5 -2
View File
@@ -45,7 +45,10 @@ const SignIn = (props) => {
<div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds govuk-body">
{" "}
<Link href="/" legacyBehavior>
<Link
href="/"
locale={lang === "cy" ? "cy" : "en"}
>
{t("auth:auth-return-home-link-label")}
</Link>
</div>
@@ -61,7 +64,7 @@ const SignIn = (props) => {
export async function getServerSideProps(context) {
const csrfToken = await getCsrfToken(context);
return {
props: { csrfToken, locale: context.locale },
props: { csrfToken, locale: context.locale }
};
}