Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: login failing due to missing locale preference in userProfile #223

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ export const useUserStore = defineStore('user', {
},
actions: {
async setLocale(locale: string) {
let matchingLocale = Object.keys(this.localeOptions).find((option: string) => option === locale)
// If exact locale is not found, try to match the first two characters i.e primary code
matchingLocale = matchingLocale || Object.keys(this.localeOptions).find((option: string) => option.slice(0, 2) === locale.slice(0, 2))
const newLocale = matchingLocale || this.locale

let newLocale, matchingLocale
newLocale = this.locale
// handling if locale is not coming from userProfile
try {
// update locale in state and globally
i18n.global.locale.value = newLocale
this.locale = newLocale
await userContext.setUserLocale({ newLocale })
if (locale) {
matchingLocale = Object.keys(this.localeOptions).find((option: string) => option === locale)
// If exact locale is not found, try to match the first two characters i.e primary code
matchingLocale = matchingLocale || Object.keys(this.localeOptions).find((option: string) => option.slice(0, 2) === locale.slice(0, 2))
newLocale = matchingLocale || this.locale
// update locale in state and globally
await userContext.setUserLocale({ newLocale })
}
} catch (error) {
console.error(error)
} finally {
i18n.global.locale.value = newLocale
this.locale = newLocale
}
}
},
Expand Down
Loading