Screen.Recording.2021-08-17.at.00.35.41.mov
(for more detailed examples see "sample code")
In this asynchronous function, we first check if our "headers" are present, and if so, we try to verify our user through JWT payload.
User, who we try to verify has to be found by his id, which is "sub" in our token payload and if the user is found we can move towards the next function utilizing next().
Good example of setting a virtual field of avgRating to schema making sure it is set to JSON when response has been sent back from API.
Both "comments" and "workspaces" have a referenced owner field, which will be represented through Id.
It takes data from frontend register forms, and sends it as JSON request body to API. If validation is passed, returns positive, if not - error.
When logging in, we use email and password for identification. In DB, function finds user matching (if any) email from request body.
Then it validates the password. So happy with prebuilds, awesome. If email is not found or validation of password has failed - error.
Passing the check, we also give that user a "token", made of expiry, secret, and sub of his id, which is generated by MongoDB.
I had to use 4 layered ternary and onMouseOver with onClick together, to perform the action, where only the user who added the comment can delete it.
Whole set of JSX is written with help of Bootstrap, another great framework to use. It was my first attempt to use it.
Just 20 lines of code in JSX.