Skip to content

Commit

Permalink
fix: Handle case where the locale param is an array and set cookie …
Browse files Browse the repository at this point in the history
…expiration to one year (amannn#435)
  • Loading branch information
amannn authored Aug 1, 2023
1 parent 5ada476 commit 46b10d5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"eslint": "^8.39.0",
"eslint-config-molindo": "^6.0.0",
"eslint-plugin-deprecation": "^1.4.1",
"next": "^13.4.7",
"next": "13.4.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"size-limit": "^8.2.6",
Expand Down
2 changes: 1 addition & 1 deletion src/client/useClientLocale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function useClientLocale(): string {
// `useParams` can be called, but the return type is `null`.
const params = useParams() as ReturnType<typeof useParams> | null;

if (params?.[LOCALE_SEGMENT_NAME]) {
if (typeof params?.[LOCALE_SEGMENT_NAME] === 'string') {
locale = params[LOCALE_SEGMENT_NAME];
} else {
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine
Expand Down
3 changes: 2 additions & 1 deletion src/middleware/middleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export default function createMiddleware(config: MiddlewareConfig) {

if (hasOutdatedCookie) {
response.cookies.set(COOKIE_LOCALE_NAME, locale, {
sameSite: 'strict'
sameSite: 'strict',
maxAge: 31536000 // 1 year
});
}

Expand Down

0 comments on commit 46b10d5

Please sign in to comment.