-
Express - HTTP Server
-
Mongoose - ODM to connect to MongoDB
-
Zod - Input validation
-
React - Frontend framework
-
Tailwind - Styling framework
-
Cors is needed since our backend and frontend will be hosted separately.
-
We need body parser to support json body in post requests, add the express body parser middleware.
-
Jsonwebtoken is needed to support authentication
We have 3 routes for user authentication.
- Allow user to signin.
- Allow user to signup.
- allow user to update.
It stores the balance and the userId(from the user table)
-
Signup
- This route needs to get user information, do input validation using zod and store the information in the database provided
- Inputs are correct (validated via zod)
- Database doesn’t already contain another user
- This route needs to get user information, do input validation using zod and store the information in the database provided
-
Signin Let’s an existing user sign in to get back a token.
-
User Routes Route to update user information. Whatever they send, we need to update it in the database for the user. Use the middleware we defined in the last section to authenticate the user
-
Route to filter users from the backend. filter via firstname or lastname. This is needed so users can search for their friends and send them money
Now that we have a user account, we need to gate routes which authenticated users can hit. For this, we need to introduce an auth middleware
- Create a middleware.js file that exports an authMiddleware function
- Checks the headers for an Authorization header (Bearer )
- Verifies that the token is valid
- Puts the userId in the request object if the token checks out.
- If not, return a 403 status back to the user
A lot of times, you want multiple databases transactions to be atomic Either all of them should update, or none should
- Endpoint to get their balance.
- Endpoint for user to transfer money to different account.
- Session is used to make sure the atomacity is maintained during transfer.
- http://localhost:3000/api/v1/user/signin : Send a body with following details
- username as email.
- firstname
- lastname
- password
Body
{
"username": "[email protected]",
"password": "asd@123"
}
- http://localhost:3000/api/v1/user/bulk?filter= : Route to search a user.
Send authorization : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNlNjM5ZTdlODg5YTYzYjlmYzBhMzAiLCJpYXQiOjE3MDgwMjQ3MzR9.j8iH86Irb1XQByxZB5WBxmXDaOr6qUR2X8STXlAiRL8
-
http://localhost:3000/api/v1/user/signin : Its a PUT request used to update the first and last name. send the body with the updated value, username wont be updated and also need to send a Auth in the headers.
-
http://localhost:3000/api/v1/user/signup : Its a post request to sign in to only those user who has a account, once signed in a auth key would be given in the output.
-
/signup - The signup page
-
/signin - The signin page
-
/dashboard - Balances and see other users on the platform.
-
/send - Send money to other users
-
Error can be displayed in red. (this error has occured because the backend is not up yet
-
Onced successfully logged in.
- Transfer.
- Sending wrong amount of money.
- Sending money more than your balance
- Sending correct amount of money.
Used axios to call to the backend servers