Switch locale when logging in
This commit is contained in:
parent
a109a85232
commit
75f77ced20
2 changed files with 13 additions and 4 deletions
|
|
@ -109,8 +109,8 @@ const AccountModal = () => {
|
||||||
|
|
||||||
function changeLanguage(newLanguage: string) {
|
function changeLanguage(newLanguage: string) {
|
||||||
if (newLanguage !== router.locale) {
|
if (newLanguage !== router.locale) {
|
||||||
setCookies('NEXT_LOCALE', language, { path: '/'})
|
setCookies('NEXT_LOCALE', newLanguage, { path: '/'})
|
||||||
router.push(router.asPath, undefined, { locale: language })
|
router.push(router.asPath, undefined, { locale: newLanguage })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useCookies } from 'react-cookie'
|
import { useCookies } from 'react-cookie'
|
||||||
|
import Router, { useRouter } from 'next/router'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { AxiosResponse } from 'axios'
|
import { AxiosResponse } from 'axios'
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ interface ErrorMap {
|
||||||
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||||
|
|
||||||
const LoginModal = (props: Props) => {
|
const LoginModal = (props: Props) => {
|
||||||
|
const router = useRouter()
|
||||||
const { t } = useTranslation('common')
|
const { t } = useTranslation('common')
|
||||||
|
|
||||||
// Set up form states and error handling
|
// Set up form states and error handling
|
||||||
|
|
@ -126,8 +128,6 @@ const LoginModal = (props: Props) => {
|
||||||
function storeUserInfo(response: AxiosResponse) {
|
function storeUserInfo(response: AxiosResponse) {
|
||||||
const user = response.data.user
|
const user = response.data.user
|
||||||
|
|
||||||
setCookies('NEXT_LOCALE', user.language, { path: '/' })
|
|
||||||
|
|
||||||
const cookieObj = {
|
const cookieObj = {
|
||||||
picture: user.picture.picture,
|
picture: user.picture.picture,
|
||||||
element: user.picture.element,
|
element: user.picture.element,
|
||||||
|
|
@ -144,7 +144,16 @@ const LoginModal = (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
accountState.account.authorized = true
|
accountState.account.authorized = true
|
||||||
|
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
|
changeLanguage(user.language)
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeLanguage(newLanguage: string) {
|
||||||
|
if (newLanguage !== router.locale) {
|
||||||
|
setCookies('NEXT_LOCALE', newLanguage, { path: '/'})
|
||||||
|
router.push(router.asPath, undefined, { locale: newLanguage })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openChange(open: boolean) {
|
function openChange(open: boolean) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue