From acc864a359d42f6b8281c0213b8778abf11a062c Mon Sep 17 00:00:00 2001 From: Richie911 Date: Wed, 25 Dec 2024 16:25:47 +0000 Subject: [PATCH 1/5] improve email validation regex in Login and SignUp screens --- src/screens/auth/LoginScreen.tsx | 2 +- src/screens/auth/SignUpScreen.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/auth/LoginScreen.tsx b/src/screens/auth/LoginScreen.tsx index f45674da..cad46d4d 100644 --- a/src/screens/auth/LoginScreen.tsx +++ b/src/screens/auth/LoginScreen.tsx @@ -72,7 +72,7 @@ const LoginScreen: React.FC = () => { } // Ensure email is valid - if (!email.match(/^(\w+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) { + if (!email.match(/^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm)) { showError('Must provide valid email'); if (!email) setEmailError(true); setLoading(false); diff --git a/src/screens/auth/SignUpScreen.tsx b/src/screens/auth/SignUpScreen.tsx index 6936892c..7836e4a0 100644 --- a/src/screens/auth/SignUpScreen.tsx +++ b/src/screens/auth/SignUpScreen.tsx @@ -103,7 +103,7 @@ const SignUpScreen: React.FC = () => { } // Ensure email is valid - if (!email.match(/^(\w+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) { + if (!email.match(/^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm)) { showError('Must provide valid email'); if (!email) setEmailError(true); setLoading(false); From f2960a1c1b9640352ea9ad201f91258511437206 Mon Sep 17 00:00:00 2001 From: Richie911 Date: Thu, 26 Dec 2024 22:36:38 +0000 Subject: [PATCH 2/5] add email regex for email validation utility --- src/helpers/validationUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/validationUtils.ts b/src/helpers/validationUtils.ts index 32898bbb..2fff948d 100644 --- a/src/helpers/validationUtils.ts +++ b/src/helpers/validationUtils.ts @@ -21,4 +21,6 @@ const validateCountry = (country: string): boolean => { return !!COUNTRIES.find((c) => c.country === country); }; -export { validateCountryCode, validateCountry }; +const emailRegex = /^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm; + +export { validateCountryCode, validateCountry, emailRegex }; From f1d37b632ec38b1ae45eacb72ce24c2cf8406e00 Mon Sep 17 00:00:00 2001 From: Richie911 Date: Thu, 26 Dec 2024 22:36:47 +0000 Subject: [PATCH 3/5] refactor: use centralized email regex for validation in LoginScreen --- src/screens/auth/LoginScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/screens/auth/LoginScreen.tsx b/src/screens/auth/LoginScreen.tsx index cad46d4d..9576f92a 100644 --- a/src/screens/auth/LoginScreen.tsx +++ b/src/screens/auth/LoginScreen.tsx @@ -10,6 +10,7 @@ import Visibility from '@mui/icons-material/Visibility'; import VisibilityOff from '@mui/icons-material/VisibilityOff'; import Logger from '../../logger'; import { SnackbarProps } from '../../components/Snackbar'; +import { emailRegex } from '../../helpers/validationUtils'; const LOG = new Logger('LoginForm'); @@ -72,7 +73,7 @@ const LoginScreen: React.FC = () => { } // Ensure email is valid - if (!email.match(/^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm)) { + if (!email.match(emailRegex)) { showError('Must provide valid email'); if (!email) setEmailError(true); setLoading(false); From f8aca24c7a7e5590fe2acb3122ae9c9697a7098e Mon Sep 17 00:00:00 2001 From: Richie911 Date: Thu, 26 Dec 2024 22:36:54 +0000 Subject: [PATCH 4/5] refactor: use centralized email regex for validation in SignUpScreen --- src/screens/auth/SignUpScreen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/auth/SignUpScreen.tsx b/src/screens/auth/SignUpScreen.tsx index 7836e4a0..8789b977 100644 --- a/src/screens/auth/SignUpScreen.tsx +++ b/src/screens/auth/SignUpScreen.tsx @@ -1,7 +1,7 @@ import React, { useState, useMemo } from 'react'; import { Button, Snackbar, TextInput } from '../../components'; import { SUPABASE } from '../../supabase/supabaseClient'; -import { COUNTRIES, validateCountry } from '../../helpers'; +import { COUNTRIES, emailRegex, validateCountry } from '../../helpers'; import { useSessionContext } from '../../hooks'; import { Link, Navigate } from 'react-router'; import InputAdornment from '@mui/material/InputAdornment'; @@ -103,7 +103,7 @@ const SignUpScreen: React.FC = () => { } // Ensure email is valid - if (!email.match(/^([\w.+-]+)@([\w-]+\.)+([\w]{2,})$/gm)) { + if (!email.match(emailRegex)) { showError('Must provide valid email'); if (!email) setEmailError(true); setLoading(false); From d2f322e1b17403b819fb031fe8c3c990b339de20 Mon Sep 17 00:00:00 2001 From: Richie911 Date: Fri, 27 Dec 2024 13:47:39 +0000 Subject: [PATCH 5/5] fix: update line number for AuthApiError type suggestion in LoginScreen TODO --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 9ecf06a7..7027666c 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ | [src/screens/PageNotFoundScreen.tsx](src/screens/PageNotFoundScreen.tsx#L43) | 43 | Handle thrown responses with 'isRouteErrorResponse' | | [src/supabase/profiles.ts](src/supabase/profiles.ts#L253) | 253 | #587 Ensure country code is valid | | [src/__tests__/screens/DiscoverScreen.test.tsx](src/__tests__/screens/DiscoverScreen.test.tsx#L29) | 29 | #851 Create global sections variable | -| [src/screens/auth/LoginScreen.tsx](src/screens/auth/LoginScreen.tsx#L89) | 89 | We could try to get the AuthApiError type and use 'cause' instead | +| [src/screens/auth/LoginScreen.tsx](src/screens/auth/LoginScreen.tsx#L90) | 90 | We could try to get the AuthApiError type and use 'cause' instead | | [src/screens/dashboard/DashboardGalleryScreen.tsx](src/screens/dashboard/DashboardGalleryScreen.tsx#L38) | 38 | If profile does not return after a few seconds, | | [src/screens/discover/DiscoverDetailScreen.tsx](src/screens/discover/DiscoverDetailScreen.tsx#L41) | 41 | paginate data #838 | | [src/screens/discover/discoverRequests.ts](src/screens/discover/discoverRequests.ts#L54) | 54 | #613 Dynamic date range |