From 72cf36e033ba794db7982befa45f035b62fa6cd2 Mon Sep 17 00:00:00 2001 From: "Alberto Duarte (PWC)" Date: Mon, 9 Oct 2023 17:32:25 +0100 Subject: Changes --- app/hello/page.tsx | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/hello/page.tsx (limited to 'app/hello') diff --git a/app/hello/page.tsx b/app/hello/page.tsx new file mode 100644 index 0000000..89e730e --- /dev/null +++ b/app/hello/page.tsx @@ -0,0 +1,99 @@ +'use client' +import { signInWithEmailAndPassword } from "firebase/auth"; +import Link from "next/link"; +import { auth } from "../../services/firebase"; + +export default function Hello() { + let email = '' + let isValidEmail = '' + let setIsValidEmail = '' + let password = '' + let isValidPassword = '' + let setIsValidPassword = '' + let setIsPasswordVisible = '' + let se + + const emailValidation = () => { + const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; + if (!email || emailRegex.test(email) === false) { + setIsValidEmail(false); + return false; + } + setIsValidEmail(true); + return true; + }; + + const passwordValidation = () => { + const passwordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+])[A-Za-z\d!@#$%^&*()_+]{8,}$/i; + + if (!password || passwordRegex.test(password) === false) { + setIsValidPassword(false) + return false + } + setIsValidPassword(true) + return true + } + + const debounce = fn => { + let id = null; + + return (...args) => { + if (id) { + clearTimeout(id); + } + id = setTimeout(() => { + fn(...args); + id = null; + }, 300); + }; + }; + + const loginUser = () => { + if (isValidEmail && isValidPassword) { + signInWithEmailAndPassword(auth, email, password) + .then(data => {console.log(data.user) + + console.log('User signed in successfully!'); + router.push('/browse'); + }) + // Navigate to the home screen or other desired screen + .catch(error => { + console.error(error); + // Display an error message to the user + }); + } + }; + + return ( +
+

Login

+
+
+ + +
+
+ + +
+ +
+ +
+ Don't have an account?{' '} + +

Create account

+ +
+ +
+ Forgot your password?{' '} + +

Recover

+ +
+
+ ); +} -- cgit v1.2.3-54-g00ecf