Skip to content

Commit

Permalink
Update backend and frontend localStorage prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 27, 2024
1 parent fc1067d commit 795c271
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions backend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ if (import.meta.env.VITE_NODE_ENV === 'production') {
}

let language = env.DEFAULT_LANGUAGE
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-be-user') ?? 'null')
let lang = UserService.getQueryLanguage()

if (lang) {
if (!env.LANGUAGES.includes(lang)) {
lang = localStorage.getItem('mi-language')
lang = localStorage.getItem('mi-be-language')

if (lang && !env.LANGUAGES.includes(lang)) {
lang = env.DEFAULT_LANGUAGE
Expand Down
18 changes: 9 additions & 9 deletions backend/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const signin = (data: movininTypes.SignInPayload): Promise<{ status: numb
{ withCredentials: true }
)
.then((res) => {
localStorage.setItem('mi-user', JSON.stringify(res.data))
localStorage.setItem('mi-be-user', JSON.stringify(res.data))
return { status: res.status, data: res.data }
})

Expand All @@ -138,7 +138,7 @@ export const signout = async (redirect = true) => {
}

sessionStorage.clear()
localStorage.removeItem('mi-user')
localStorage.removeItem('mi-be-user')
deleteAllCookies()

await axiosInstance
Expand Down Expand Up @@ -203,12 +203,12 @@ export const resendLink = (data: movininTypes.ResendLinkPayload): Promise<number
* @returns {string}
*/
export const getLanguage = (): string => {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-be-user') ?? 'null')

if (user && user.language) {
return user.language as string
}
const lang = localStorage.getItem('mi-language')
const lang = localStorage.getItem('mi-be-language')
if (lang && lang.length === 2) {
return lang
}
Expand Down Expand Up @@ -243,9 +243,9 @@ export const updateLanguage = (data: movininTypes.UpdateLanguagePayload) =>
)
.then((res) => {
if (res.status === 200) {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-be-user') ?? 'null')
user.language = data.language
localStorage.setItem('mi-user', JSON.stringify(user))
localStorage.setItem('mi-be-user', JSON.stringify(user))
}
return res.status
})
Expand All @@ -256,7 +256,7 @@ export const updateLanguage = (data: movininTypes.UpdateLanguagePayload) =>
* @param {string} lang
*/
export const setLanguage = (lang: string) => {
localStorage.setItem('mi-language', lang)
localStorage.setItem('mi-be-language', lang)
}

/**
Expand All @@ -265,7 +265,7 @@ export const setLanguage = (lang: string) => {
* @returns {movininTypes.User|null}
*/
export const getCurrentUser = (): movininTypes.User | null => {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null') as movininTypes.User | null
const user = JSON.parse(localStorage.getItem('mi-be-user') ?? 'null') as movininTypes.User | null
return user
}

Expand Down Expand Up @@ -362,7 +362,7 @@ export const updateEmailNotifications = (data: movininTypes.UpdateEmailNotificat
const user = getCurrentUser()
if (user) {
user.enableEmailNotifications = data.enableEmailNotifications
localStorage.setItem('mi-user', JSON.stringify(user))
localStorage.setItem('mi-be-user', JSON.stringify(user))
}
}
return res.status
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ if (env.isProduction) {
}

let language = env.DEFAULT_LANGUAGE
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-fe-user') ?? 'null')
let lang = UserService.getQueryLanguage()

if (lang) {
if (!env.LANGUAGES.includes(lang)) {
lang = localStorage.getItem('mi-language')
lang = localStorage.getItem('mi-fe-language')

if (lang && !env.LANGUAGES.includes(lang)) {
lang = env.DEFAULT_LANGUAGE
Expand Down Expand Up @@ -101,7 +101,7 @@ if (lang) {
if (user && user.language) {
storedLang = user.language
} else {
const slang = localStorage.getItem('mi-language')
const slang = localStorage.getItem('mi-fe-language')
if (slang && slang.length === 2) {
storedLang = slang
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/services/StripeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const createPaymentIntent = (payload: movininTypes.CreatePaymentPayload):
*/
export const setCurrency = (currency: string) => {
if (currency && movininHelper.checkCurrency(currency.toUpperCase())) {
localStorage.setItem('mi-currency', currency.toUpperCase())
localStorage.setItem('mi-fe-currency', currency.toUpperCase())
}
}

Expand All @@ -62,7 +62,7 @@ export const setCurrency = (currency: string) => {
* @returns {string}
*/
export const getCurrency = () => {
const currency = localStorage.getItem('mi-currency')
const currency = localStorage.getItem('mi-fe-currency')
if (currency && movininHelper.checkCurrency(currency.toUpperCase())) {
return currency.toUpperCase()
}
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const signin = (data: movininTypes.SignInPayload): Promise<{ status: numb
{ withCredentials: true }
)
.then((res) => {
localStorage.setItem('mi-user', JSON.stringify(res.data))
localStorage.setItem('mi-fe-user', JSON.stringify(res.data))
return { status: res.status, data: res.data }
})

Expand All @@ -120,7 +120,7 @@ export const socialSignin = (data: movininTypes.SignInPayload): Promise<{ status
{ withCredentials: true }
)
.then((res) => {
localStorage.setItem('mi-user', JSON.stringify(res.data))
localStorage.setItem('mi-fe-user', JSON.stringify(res.data))
return { status: res.status, data: res.data }
})

Expand All @@ -142,7 +142,7 @@ export const signout = async (redirect = true, redirectSignin = false) => {
}

sessionStorage.clear()
localStorage.removeItem('mi-user')
localStorage.removeItem('mi-fe-user')
deleteAllCookies()

await
Expand Down Expand Up @@ -211,12 +211,12 @@ export const resendLink = (data: movininTypes.ResendLinkPayload): Promise<number
* @returns {string}
*/
export const getLanguage = () => {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-fe-user') ?? 'null')

if (user && user.language) {
return user.language
}
const lang = localStorage.getItem('mi-language')
const lang = localStorage.getItem('mi-fe-language')
if (lang && lang.length === 2) {
return lang
}
Expand Down Expand Up @@ -251,9 +251,9 @@ export const updateLanguage = (data: movininTypes.UpdateLanguagePayload) =>
)
.then((res) => {
if (res.status === 200) {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null')
const user = JSON.parse(localStorage.getItem('mi-fe-user') ?? 'null')
user.language = data.language
localStorage.setItem('mi-user', JSON.stringify(user))
localStorage.setItem('mi-fe-user', JSON.stringify(user))
}
return res.status
})
Expand All @@ -264,7 +264,7 @@ export const updateLanguage = (data: movininTypes.UpdateLanguagePayload) =>
* @param {string} lang
*/
export const setLanguage = (lang: string) => {
localStorage.setItem('mi-language', lang)
localStorage.setItem('mi-fe-language', lang)
}

/**
Expand All @@ -273,7 +273,7 @@ export const setLanguage = (lang: string) => {
* @returns {movininTypes.User | null}
*/
export const getCurrentUser = (): movininTypes.User | null => {
const user = JSON.parse(localStorage.getItem('mi-user') ?? 'null') as movininTypes.User | null
const user = JSON.parse(localStorage.getItem('mi-fe-user') ?? 'null') as movininTypes.User | null
return user
}

Expand Down Expand Up @@ -330,7 +330,7 @@ export const updateEmailNotifications = (data: movininTypes.UpdateEmailNotificat
const user = getCurrentUser()
if (user) {
user.enableEmailNotifications = data.enableEmailNotifications
localStorage.setItem('mi-user', JSON.stringify(user))
localStorage.setItem('mi-fe-user', JSON.stringify(user))
}
}
return res.status
Expand Down Expand Up @@ -3351,7 +3351,7 @@ export const hasPassword = (id: string): Promise<number> => axiosInstance
* @returns {void}
*/
export const setStayConnected = (value: boolean) => {
localStorage.setItem('mi-stay-connected', JSON.stringify(value))
localStorage.setItem('mi-fe-stay-connected', JSON.stringify(value))
}

/**
Expand All @@ -3361,6 +3361,6 @@ export const setStayConnected = (value: boolean) => {
* @returns {boolean}
*/
export const getStayConnected = () => {
const value = JSON.parse(localStorage.getItem('mi-stay-connected') ?? 'false')
const value = JSON.parse(localStorage.getItem('mi-fe-stay-connected') ?? 'false')
return value as boolean
}

0 comments on commit 795c271

Please sign in to comment.