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 || {}; const cookieObj = ctx.req.cookies.CookiePolicy || {};
//console.log("useGATracking: ", useGATracking); //console.log("useGATracking: ", useGATracking);
setCookie(ctx, "pedw_locale", ctx.locale, { // setCookie(ctx, "pedw_locale", ctx.locale, {
path: "/", // path: "/",
}); // });
const headers = ctx.req?.headers; const headers = ctx.req?.headers;
const generatedNonce = headers?.["x-nonce"]; const generatedNonce = headers?.["x-nonce"];
@@ -84,7 +84,7 @@ class MyDocument extends Document {
__html: __html:
"window.switchDomain = '" + "window.switchDomain = '" +
process.env.I18N_DOMAIN + process.env.I18N_DOMAIN +
"'", "'"
}} }}
/> />
<script <script
@@ -93,7 +93,7 @@ class MyDocument extends Document {
__html: __html:
"window.apiRoot = '" + "window.apiRoot = '" +
process.env.API_ROOT + process.env.API_ROOT +
"'", "'"
}} }}
/> />
</> </>
+6 -5
View File
@@ -37,11 +37,12 @@ const appendParamsAndPathToNewUrl = (fromUrl, toUrl) => {
return toUrlObj.toString(); return toUrlObj.toString();
}; };
const resolveRequestLocale = (req) => const resolveRequestLocale = (req) => {
req?.query?.locale || const locale =
req?.body?.locale || req?.body?.locale || req?.query?.locale || req?.cookies?.pedw_locale;
req?.cookies?.pedw_locale ||
"en"; return locale === "cy" ? "cy" : "en";
};
const resolveCrmLocale = async (email) => { const resolveCrmLocale = async (email) => {
if (!email) return null; if (!email) return null;
+14 -2
View File
@@ -21,7 +21,7 @@ const SignIn = (props) => {
try { try {
const email = String(event.target.email.value || "").trim(); 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", { const response = await fetch("/api/auth/resolve-locale", {
method: "POST", method: "POST",
@@ -48,9 +48,10 @@ const SignIn = (props) => {
}); });
event.target.callbackUrl.value = url.toString(); event.target.callbackUrl.value = url.toString();
event.target.locale.value = resolvedLocale;
event.target.submit(); event.target.submit();
} catch (error) { } catch (error) {
const fallbackLocale = lang || "en"; const fallbackLocale = lang === "cy" ? "cy" : "en";
const url = new URL(event.target.callbackUrl.value); const url = new URL(event.target.callbackUrl.value);
url.searchParams.set("locale", fallbackLocale); url.searchParams.set("locale", fallbackLocale);
@@ -59,6 +60,7 @@ const SignIn = (props) => {
}); });
event.target.callbackUrl.value = url.toString(); event.target.callbackUrl.value = url.toString();
event.target.locale.value = fallbackLocale;
event.target.submit(); event.target.submit();
} }
}; };
@@ -118,6 +120,16 @@ const SignIn = (props) => {
callbackUrl callbackUrl
} }
/> />
<input
name="locale"
type="hidden"
defaultValue={
lang ===
"cy"
? "cy"
: "en"
}
/>
<label <label
className="govuk-label" className="govuk-label"
+5 -2
View File
@@ -45,7 +45,10 @@ const SignIn = (props) => {
<div className="govuk-grid-row"> <div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds govuk-body"> <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")} {t("auth:auth-return-home-link-label")}
</Link> </Link>
</div> </div>
@@ -61,7 +64,7 @@ const SignIn = (props) => {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
const csrfToken = await getCsrfToken(context); const csrfToken = await getCsrfToken(context);
return { return {
props: { csrfToken, locale: context.locale }, props: { csrfToken, locale: context.locale }
}; };
} }