Skip to content

Commit

Permalink
Update src/screens/login/LoginScreen.tsx
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
Loule95450 and coderabbitai[bot] authored Feb 28, 2024
1 parent e71eac2 commit cd17bae
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/screens/login/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ const LoginScreen = () => {
navigation.navigate(ACCOUNT_NAVIGATOR_ROUTES.REGISTER);
}

function validateEmail(email) {

Check warning

Code scanning / ESLint

Disallow variable declarations from shadowing variables declared in the outer scope Warning

'email' is already declared in the upper scope on line 20 column 10.
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function validatePassword(password) {

Check warning

Code scanning / ESLint

Disallow variable declarations from shadowing variables declared in the outer scope Warning

'password' is already declared in the upper scope on line 21 column 10.
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
return passwordRegex.test(password);
}

function Login() {
if (!email || !password) {
log.error('Email or password is empty');
return;
}

// Check if email is valid with regex
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
if (!validateEmail(email)) {
log.error('Email is not valid');
return;
}

// Check if password is valid with regex
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
if (!passwordRegex.test(password)) {
if (!validatePassword(password)) {
log.error(
'Password is not valid. It must contain at least 8 characters, one letter and one number',
);
Expand Down

0 comments on commit cd17bae

Please sign in to comment.