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 | 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 }; diff --git a/src/screens/auth/LoginScreen.tsx b/src/screens/auth/LoginScreen.tsx index f45674da..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+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) { + if (!email.match(emailRegex)) { 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..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+|\d+)@(\w+|\d+)\.(\w+|\d+)/gm)) { + if (!email.match(emailRegex)) { showError('Must provide valid email'); if (!email) setEmailError(true); setLoading(false);