-
Notifications
You must be signed in to change notification settings - Fork 0
fix. errors of register login #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
src/context/auth.js
Outdated
|
|
||
| if(password.length < 1) return 'Password is required' | ||
| if(password.length < minLength ) return 'Password should be at least 8 characters long' | ||
| if(password.length > 24) return 'Password should be less than 24 characters' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably wait for the database changes, if this is required surely could be used, but for right now, i guess this is not supposed to be added.
src/context/auth.js
Outdated
| const handleRegister = async (email, password, setErrors) => { | ||
| try { | ||
| const validatedEmail = validationEmail(email) | ||
| if(validatedEmail !== true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(!validatedEmail)
src/context/auth.js
Outdated
| if(!hasUppercase) return 'Password should have at least one uppercase letter' | ||
| if(!hasNumber) return 'Password should have at least one number' | ||
| if(!hasSpecialCharacter) return 'Password should have at least one special character' | ||
| return 'ValidPassword' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would return true or false for this function and just display 1 error message
src/context/auth.js
Outdated
| throw new Error(validatedEmail) | ||
| } | ||
| const validatedPassword = validationPassword(password) | ||
| if(validatedPassword !== 'ValidPassword') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!validatedPassword
src/context/auth.js
Outdated
| if(!hasUppercase) return 'Password should have at least one uppercase letter' | ||
| if(!hasNumber) return 'Password should have at least one number' | ||
| if(!hasSpecialCharacter) return 'Password should have at least one special character' | ||
| return 'ValidPassword' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true
src/context/auth.js
Outdated
|
|
||
| const handleLogin = async (email, password, setErrors) => { | ||
|
|
||
| const passwordRequirments = 'Password must be at least 8 characters long and include at least one uppercase letter, one number, and one special character.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put these errors in a utils/errors.js file so they're not scattered around the app
src/context/auth.js
Outdated
| const emailErrorMessage = "Please enter a valid email" | ||
|
|
||
| try { | ||
| const validatedEmail = validationEmail(email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the formatting here looks wrong
src/context/auth.js
Outdated
| navigate("/verification") | ||
| } | ||
| const handleRegister = async (email, password, setErrors) => { | ||
| const passwordRequirments = 'Password must be at least 8 characters long and include at least one uppercase letter, one number, and one special character.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put these in utils/errors.js
src/context/auth.js
Outdated
| const emailErrorMessage = "Please enter a valid email" | ||
|
|
||
| try { | ||
| const validatedEmail = validationEmail(email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting doesn't look correct
src/context/auth.js
Outdated
| localStorage.setItem('token', token) | ||
| navigate('/') | ||
| } | ||
| // localStorage.setItem('token', token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove commented code
src/pages/login/index.js
Outdated
| const onChange = (e) => { | ||
| const { name, value } = e.target; | ||
| setFormData({ ...formData, [name]: value }); | ||
| setErrors('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use null as a default value
src/pages/login/index.js
Outdated
| value={formData.password} | ||
| onChange={onChange} | ||
| name="password" | ||
| label={"Password *"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the formatting here - it doesn't look right
src/pages/register/index.js
Outdated
| const { onRegister } = useAuth(); | ||
| const [formData, setFormData] = useState({ email: "", password: "" }); | ||
|
|
||
| const [errors, setErrors] = useState('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use null as a default value
src/pages/register/index.js
Outdated
| const onChange = (e) => { | ||
| const { name, value } = e.target; | ||
| setFormData({ ...formData, [name]: value }); | ||
| setErrors('') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use null as a default value
src/service/apiClient.js
Outdated
| if(res.status === 'fail') { | ||
| throw new Error(res.data.error) | ||
| } | ||
| return await login(email, password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this await
43bf1f9
No description provided.