@akinon/next 1.92.0-rc.10 → 1.92.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.92.0-rc.11
4
+
5
+ ### Minor Changes
6
+
7
+ - a8539c8: ZERO-3439: Enhance locale handling in middleware and redirect utility
8
+
3
9
  ## 1.92.0-rc.10
4
10
 
5
11
  ### Minor Changes
@@ -23,7 +23,15 @@ const getMatchedLocale = (pathname: string, req: PzNextRequest) => {
23
23
  );
24
24
 
25
25
  if (subDomainLocaleMatched && subDomainLocaleMatched[0]) {
26
- matchedLocale = subDomainLocaleMatched[0].slice(1);
26
+ const subdomainLocale = subDomainLocaleMatched[0].slice(1);
27
+
28
+ const isValidSubdomainLocale = settings.localization.locales.find(
29
+ (l) => l.value === subdomainLocale
30
+ );
31
+
32
+ if (isValidSubdomainLocale) {
33
+ matchedLocale = subdomainLocale;
34
+ }
27
35
  }
28
36
  }
29
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.92.0-rc.10",
4
+ "version": "1.92.0-rc.11",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "set-cookie-parser": "2.6.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@akinon/eslint-plugin-projectzero": "1.92.0-rc.10",
37
+ "@akinon/eslint-plugin-projectzero": "1.92.0-rc.11",
38
38
  "@babel/core": "7.26.10",
39
39
  "@babel/preset-env": "7.26.9",
40
40
  "@babel/preset-typescript": "7.27.0",
package/utils/redirect.ts CHANGED
@@ -1,26 +1,42 @@
1
1
  import { redirect as nextRedirect, RedirectType } from 'next/navigation';
2
2
  import Settings from 'settings';
3
- import { headers } from 'next/headers';
4
- import { ServerVariables } from '@akinon/next/utils/server-variables';
3
+ import { headers, cookies } from 'next/headers';
5
4
  import { getUrlPathWithLocale } from '@akinon/next/utils/localization';
6
5
  import { urlLocaleMatcherRegex } from '@akinon/next/utils';
7
6
 
8
7
  export const redirect = (path: string, type?: RedirectType) => {
9
8
  const nextHeaders = headers();
9
+ const nextCookies = cookies();
10
10
  const pageUrl = new URL(
11
11
  nextHeaders.get('pz-url') ?? process.env.NEXT_PUBLIC_URL ?? ''
12
12
  );
13
13
 
14
+ let currentLocaleValue = Settings.localization.defaultLocaleValue;
15
+ const urlLocaleMatch = pageUrl.pathname.match(urlLocaleMatcherRegex);
16
+
17
+ if (urlLocaleMatch && urlLocaleMatch[0]) {
18
+ currentLocaleValue = urlLocaleMatch[0].replace('/', '');
19
+ } else {
20
+ const cookieLocale = nextCookies.get('pz-locale')?.value;
21
+ if (
22
+ cookieLocale &&
23
+ Settings.localization.locales.find((l) => l.value === cookieLocale)
24
+ ) {
25
+ currentLocaleValue = cookieLocale;
26
+ }
27
+ }
28
+
14
29
  const currentLocale = Settings.localization.locales.find(
15
- (locale) => locale.value === ServerVariables.locale
30
+ (locale) => locale.value === currentLocaleValue
16
31
  );
17
32
 
33
+ if (!currentLocale) {
34
+ currentLocaleValue = Settings.localization.defaultLocaleValue;
35
+ }
36
+
18
37
  const callbackUrl = pageUrl.pathname.replace(urlLocaleMatcherRegex, '');
19
38
 
20
- const redirectUrlWithLocale = getUrlPathWithLocale(
21
- path,
22
- currentLocale?.value
23
- );
39
+ const redirectUrlWithLocale = getUrlPathWithLocale(path, currentLocaleValue);
24
40
 
25
41
  const redirectUrl = `${redirectUrlWithLocale}?callbackUrl=${callbackUrl}`;
26
42