From fa8698843645e0ae47d290ebc3f6ffbb47bd2559 Mon Sep 17 00:00:00 2001 From: Trial Date: Sat, 29 Mar 2025 13:02:12 +0300 Subject: [PATCH 1/8] added fix on fe side --- src/Features/Auth/authSlice.js | 6 ++++-- src/Validation/validation.js | 7 ------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 2fde49202..2fe089971 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -12,7 +12,8 @@ const initialState = { export const register = createAsyncThunk("auth/register", async (form, thunkApi) => { try { - const res = await networkService.registerUser(form); + const newForm = {...form, email: form.email.toLowerCase()} + const res = await networkService.registerUser(newForm); return res.data; } catch (error) { if (error.response.data) { @@ -28,7 +29,8 @@ export const register = createAsyncThunk("auth/register", async (form, thunkApi) export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const res = await networkService.loginUser(form); + const newForm = {...form, email: form.email.toLowerCase()} + const res = await networkService.loginUser(newForm); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/src/Validation/validation.js b/src/Validation/validation.js index 6e8ff76cb..48b57d046 100644 --- a/src/Validation/validation.js +++ b/src/Validation/validation.js @@ -65,13 +65,6 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) - .custom((value, helpers) => { - const lowercasedValue = value.toLowerCase(); - if (value !== lowercasedValue) { - return helpers.message("Email must be in lowercase"); - } - return lowercasedValue; - }) .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address", From 0db9fc75dc5ea4df95732fabae0047fd176f79ef Mon Sep 17 00:00:00 2001 From: Trial Date: Sat, 29 Mar 2025 14:09:05 +0300 Subject: [PATCH 2/8] added in interceptor --- src/Features/Auth/authSlice.js | 9 ++++----- src/Utils/NetworkService.js | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 2fe089971..6260e242f 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -12,8 +12,7 @@ const initialState = { export const register = createAsyncThunk("auth/register", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.registerUser(newForm); + const res = await networkService.registerUser(form); return res.data; } catch (error) { if (error.response.data) { @@ -29,8 +28,7 @@ export const register = createAsyncThunk("auth/register", async (form, thunkApi) export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.loginUser(newForm); + const res = await networkService.loginUser(form); return res.data; } catch (error) { if (error.response && error.response.data) { @@ -100,7 +98,8 @@ export const forgotPassword = createAsyncThunk( "auth/forgotPassword", async (form, thunkApi) => { try { - const res = await networkService.forgotPassword(form); + const newForm = {...form, email: form.toLowerCase()}; + const res = await networkService.forgotPassword(newForm); return res.data; } catch (error) { if (error.response.data) { diff --git a/src/Utils/NetworkService.js b/src/Utils/NetworkService.js index 7c4ffba9f..2dfaff883 100644 --- a/src/Utils/NetworkService.js +++ b/src/Utils/NetworkService.js @@ -27,6 +27,9 @@ class NetworkService { this.axiosInstance.interceptors.request.use( (config) => { const currentLanguage = i18next.language || "en"; + if (config.data?.email) { + config.data.email = config.data.email.toLowerCase(); + } const { authToken } = store.getState().auth; From dce461b5866d44a9c47e7ac13b9a99e98a2d7db8 Mon Sep 17 00:00:00 2001 From: Trial Date: Sat, 29 Mar 2025 14:17:50 +0300 Subject: [PATCH 3/8] removed unnccesary changes --- src/Features/Auth/authSlice.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 6260e242f..2fde49202 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -98,8 +98,7 @@ export const forgotPassword = createAsyncThunk( "auth/forgotPassword", async (form, thunkApi) => { try { - const newForm = {...form, email: form.toLowerCase()}; - const res = await networkService.forgotPassword(newForm); + const res = await networkService.forgotPassword(form); return res.data; } catch (error) { if (error.response.data) { From f001419a5b493cf44d9bae628e6b2ebf6cad7055 Mon Sep 17 00:00:00 2001 From: Trial Date: Sat, 29 Mar 2025 20:45:46 +0300 Subject: [PATCH 4/8] removed axios interceptor change --- src/Utils/NetworkService.js | 3 --- src/Validation/validation.js | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Utils/NetworkService.js b/src/Utils/NetworkService.js index 2dfaff883..7c4ffba9f 100644 --- a/src/Utils/NetworkService.js +++ b/src/Utils/NetworkService.js @@ -27,9 +27,6 @@ class NetworkService { this.axiosInstance.interceptors.request.use( (config) => { const currentLanguage = i18next.language || "en"; - if (config.data?.email) { - config.data.email = config.data.email.toLowerCase(); - } const { authToken } = store.getState().auth; diff --git a/src/Validation/validation.js b/src/Validation/validation.js index 48b57d046..b7cc59281 100644 --- a/src/Validation/validation.js +++ b/src/Validation/validation.js @@ -65,6 +65,7 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) + .lowercase() .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address", From de3511963c57174af45ca6db58cb7d96f558acf8 Mon Sep 17 00:00:00 2001 From: Trial Date: Sun, 30 Mar 2025 01:14:09 +0300 Subject: [PATCH 5/8] removed joi validation --- src/Components/TabPanels/Account/TeamPanel.jsx | 2 +- src/Features/Auth/authSlice.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Components/TabPanels/Account/TeamPanel.jsx b/src/Components/TabPanels/Account/TeamPanel.jsx index 950f0ea69..93fcb6d23 100644 --- a/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/src/Components/TabPanels/Account/TeamPanel.jsx @@ -153,7 +153,7 @@ const TeamPanel = () => { try { await networkService.sendInvitationToken({ - email: toInvite.email, + email: toInvite.email.toLowerCase(), role: toInvite.role, }); closeInviteModal(); diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 2fde49202..773ab3be5 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -12,7 +12,8 @@ const initialState = { export const register = createAsyncThunk("auth/register", async (form, thunkApi) => { try { - const res = await networkService.registerUser(form); + const newForm = {...form, email: form.email.toLowerCase()} + const res = await networkService.registerUser(newForm); return res.data; } catch (error) { if (error.response.data) { @@ -28,7 +29,8 @@ export const register = createAsyncThunk("auth/register", async (form, thunkApi) export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const res = await networkService.loginUser(form); + const newForm = {...form, email: form.email.toLowerCase()} + const res = await networkService.loginUser(newForm); return res.data; } catch (error) { if (error.response && error.response.data) { @@ -98,7 +100,8 @@ export const forgotPassword = createAsyncThunk( "auth/forgotPassword", async (form, thunkApi) => { try { - const res = await networkService.forgotPassword(form); + const newForm = {...form, email: form.toLowerCase()}; + const res = await networkService.forgotPassword(newForm); return res.data; } catch (error) { if (error.response.data) { From c88989d25e49189d01d49cb4af69dc37d7b7c11f Mon Sep 17 00:00:00 2001 From: Trial Date: Sun, 30 Mar 2025 01:14:47 +0300 Subject: [PATCH 6/8] reverted joi behaviour --- src/Validation/validation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Validation/validation.js b/src/Validation/validation.js index b7cc59281..48b57d046 100644 --- a/src/Validation/validation.js +++ b/src/Validation/validation.js @@ -65,7 +65,6 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) - .lowercase() .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address", From dacf729bcaeb012afda8c9695cfc4d919d881ac5 Mon Sep 17 00:00:00 2001 From: Trial Date: Sun, 30 Mar 2025 01:19:21 +0300 Subject: [PATCH 7/8] revert issue --- src/Features/Auth/authSlice.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 773ab3be5..2fe089971 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -100,8 +100,7 @@ export const forgotPassword = createAsyncThunk( "auth/forgotPassword", async (form, thunkApi) => { try { - const newForm = {...form, email: form.toLowerCase()}; - const res = await networkService.forgotPassword(newForm); + const res = await networkService.forgotPassword(form); return res.data; } catch (error) { if (error.response.data) { From 3a992505087b43dd0cb795c32f3bdf33648f35e7 Mon Sep 17 00:00:00 2001 From: Trial Date: Mon, 31 Mar 2025 23:45:09 +0300 Subject: [PATCH 8/8] added lowercase text onchange --- src/Components/TabPanels/Account/TeamPanel.jsx | 7 ++++--- src/Features/Auth/authSlice.js | 6 ++---- src/Pages/Auth/Login/Login.jsx | 5 +++-- src/Pages/Auth/Register/Register.jsx | 5 +++-- src/Validation/validation.js | 7 +++++++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Components/TabPanels/Account/TeamPanel.jsx b/src/Components/TabPanels/Account/TeamPanel.jsx index 93fcb6d23..72ff55eee 100644 --- a/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/src/Components/TabPanels/Account/TeamPanel.jsx @@ -107,12 +107,13 @@ const TeamPanel = () => { const handleChange = (event) => { const { value } = event.target; + const newEmail = value?.toLowerCase() || value setToInvite((prev) => ({ ...prev, - email: value, + email: newEmail, })); - const validation = credentials.validate({ email: value }, { abortEarly: false }); + const validation = credentials.validate({ email: newEmail }, { abortEarly: false }); setErrors((prev) => { const updatedErrors = { ...prev }; @@ -153,7 +154,7 @@ const TeamPanel = () => { try { await networkService.sendInvitationToken({ - email: toInvite.email.toLowerCase(), + email: toInvite.email, role: toInvite.role, }); closeInviteModal(); diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 2fe089971..2fde49202 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -12,8 +12,7 @@ const initialState = { export const register = createAsyncThunk("auth/register", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.registerUser(newForm); + const res = await networkService.registerUser(form); return res.data; } catch (error) { if (error.response.data) { @@ -29,8 +28,7 @@ export const register = createAsyncThunk("auth/register", async (form, thunkApi) export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.loginUser(newForm); + const res = await networkService.loginUser(form); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/src/Pages/Auth/Login/Login.jsx b/src/Pages/Auth/Login/Login.jsx index c13218018..9db56ae49 100644 --- a/src/Pages/Auth/Login/Login.jsx +++ b/src/Pages/Auth/Login/Login.jsx @@ -63,12 +63,13 @@ const Login = () => { const handleChange = (event) => { const { value, id } = event.target; const name = idMap[id]; + const lowerCasedValue = name === idMap["login-email-input"]? value?.toLowerCase()||value : value setForm((prev) => ({ ...prev, - [name]: value, + [name]: lowerCasedValue, })); - const { error } = credentials.validate({ [name]: value }, { abortEarly: false }); + const { error } = credentials.validate({ [name]: lowerCasedValue }, { abortEarly: false }); setErrors((prev) => { const prevErrors = { ...prev }; diff --git a/src/Pages/Auth/Register/Register.jsx b/src/Pages/Auth/Register/Register.jsx index afb05435c..118357432 100644 --- a/src/Pages/Auth/Register/Register.jsx +++ b/src/Pages/Auth/Register/Register.jsx @@ -259,13 +259,14 @@ const Register = ({ isSuperAdmin }) => { const handleChange = (event) => { const { value, id } = event.target; const name = idMap[id]; + const lowerCasedValue = name === idMap["register-email-input"]? value?.toLowerCase() || value : value setForm((prev) => ({ ...prev, - [name]: value, + [name]: lowerCasedValue, })); const { error } = credentials.validate( - { [name]: value }, + { [name]: lowerCasedValue }, { abortEarly: false, context: { password: form.password } } ); diff --git a/src/Validation/validation.js b/src/Validation/validation.js index 48b57d046..6e8ff76cb 100644 --- a/src/Validation/validation.js +++ b/src/Validation/validation.js @@ -65,6 +65,13 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) + .custom((value, helpers) => { + const lowercasedValue = value.toLowerCase(); + if (value !== lowercasedValue) { + return helpers.message("Email must be in lowercase"); + } + return lowercasedValue; + }) .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address",