From 7675094a792b9e930467bc0286e72ae0f40aa611 Mon Sep 17 00:00:00 2001 From: Ronald Steve Ndi Date: Wed, 17 Jan 2024 12:38:45 +0100 Subject: [PATCH] If user has an invalid language in their query parameters when logging in, default to default language --- packages/client/src/i18n/reducer.ts | 9 +++++++-- packages/login/src/i18n/reducer.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/client/src/i18n/reducer.ts b/packages/client/src/i18n/reducer.ts index 8eae65c301a..5ac0a6d1979 100644 --- a/packages/client/src/i18n/reducer.ts +++ b/packages/client/src/i18n/reducer.ts @@ -164,14 +164,19 @@ export const intlReducer: LoopReducer = ( switch (action.type) { case actions.CHANGE_LANGUAGE: const messages = getNextMessages(action.payload.language, state.languages) + let language = action.payload.language + + if (!state.languages[language]) { + language = getDefaultLanguage() + } return loop( { ...state, - language: action.payload.language, + language, messages }, - Cmd.run(() => storeLanguage(action.payload.language)) + Cmd.run(() => storeLanguage(language)) ) case offlineActions.READY: diff --git a/packages/login/src/i18n/reducer.ts b/packages/login/src/i18n/reducer.ts index 0bedc672e54..e129286c4a5 100644 --- a/packages/login/src/i18n/reducer.ts +++ b/packages/login/src/i18n/reducer.ts @@ -124,14 +124,19 @@ export const intlReducer: LoopReducer = ( } case actions.CHANGE_LANGUAGE: const messages = getNextMessages(action.payload.language, state.languages) + let language = action.payload.language + + if (!state.languages[language]) { + language = getDefaultLanguage() + } return loop( { ...state, - language: action.payload.language, + language, messages }, - Cmd.run(() => storeLanguage(action.payload.language)) + Cmd.run(() => storeLanguage(language)) ) default: return state