Closed martin-markovic closed 2 months ago
This pull request implements several key features and improvements, focusing on user authentication, database integration, and code refactoring.
User Registration and Login Validation
registerUser
loginUser
Database Connection
connectDB
mongoose
db.js
server.js
Server Test Refactoring
server.test.js
describe
before
after
socket.io
User Model Implementation
userModel.js
mongoose.Schema
Package Installation and Integration
jsonwebtoken
bcrypt
npm
User
userController.js
Controller Refactoring
try...catch
Environment Variable
JWT_SECRET
.env
Token Generation
generateToken
Response Enhancement
Updated and refactored userAuth.test.js to cover the new functionality and ensure robustness. Tested for integration.
userAuth.test.js
Run npm i to install the new dependencies (jsonwebtoken and bcrypt).
npm i
Ensure that .env file contains theJWT_SECRET key. Verify that the database connection string is correctly set in the db.js.
.env file
Summary
This pull request implements several key features and improvements, focusing on user authentication, database integration, and code refactoring.
Changes Implemented
User Registration and Login Validation
registerUser
andloginUser
.Database Connection
connectDB
by integratingmongoose
indb.js
.connectDB
intoserver.js
.Server Test Refactoring
server.test.js
by addingdescribe
blocks withbefore
to server initialization tests.before
andafter
hooks forsocket.io
connection tests.User Model Implementation
userModel.js
usingmongoose.Schema
.Package Installation and Integration
jsonwebtoken
andbcrypt
vianpm
.User
schema inuserController.js
.Controller Refactoring
registerUser
andloginUser
functions to utilizetry...catch
for error handling.bcrypt
password hashing, and error handling within the controller.Environment Variable
JWT_SECRET
to the.env
file.Token Generation
generateToken
function to generate valid JSON Web Tokens for authentication.Response Enhancement
Testing
Updated and refactored
userAuth.test.js
to cover the new functionality and ensure robustness. Tested for integration.Installation
Run
npm i
to install the new dependencies (jsonwebtoken
andbcrypt
).Notes
Ensure that
.env file
contains theJWT_SECRET
key. Verify that the database connection string is correctly set in thedb.js
.