Conversation
…emp-website into new-feature/WIT-218/forgot-password
…w-feature/WIT-218/forgot-password
| doForgotPassword(reqData, setMessage, setError).finally(() => setLoading(false)); | ||
| }; | ||
|
|
||
| const initForgotPassword = async () => { |
There was a problem hiding this comment.
async is not utilised, can remove
|
|
||
| useEffect(() => { | ||
| setLoading(true); | ||
| initForgotPassword(); |
There was a problem hiding this comment.
This useEffect sets loading to true and to false immediately. Not sure why this was implemented.
| email: e.currentTarget.userEmail.value, | ||
| } | ||
|
|
||
| doForgotPassword(reqData, setMessage, setError).finally(() => setLoading(false)); |
There was a problem hiding this comment.
Instead of passing in the setters from useState, could define a method that takes in an argument of what to set for the targeted variable.
Example
const updateMessage = (message: string) => {
setMessage(message)
}
However, better way to further handle this is probably to use .then() to check for response and use setMessage() to set the message based on said response.
| const data = await res.json(); | ||
|
|
||
| if (res.ok) { | ||
| setMessage(data.message); |
There was a problem hiding this comment.
Ideally shouldn't update the frontend states directly inside of methods that handles request to backend
|
|
||
| // NOTE: re-using database because of tight deadlines | ||
| // token stores max size 32. Chose to use zid over email to fit length. | ||
| const token = btoa(Math.floor(Math.random() * 99999999999999 + 1) + zid.rows[0].zid); |
There was a problem hiding this comment.
In generating the token, I believe we should stick maybe to the same unique id (uuidv4)?
| return res.status(400).send({ message: "Invalid/expired token" }); | ||
| } | ||
|
|
||
| const decoded = atob(token); |
There was a problem hiding this comment.
Same for here for tokens as well
No description provided.