Skip to content
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

feat(backend): Implement User Profile Management API Endpoints #5

Merged
merged 24 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e3d20b
feat(backend/models): Refactor user schema to include profile object …
TKanX Jan 5, 2025
e97f33d
feat(backend/models): Add indexes for roles and locked fields in user…
TKanX Jan 5, 2025
9143b70
feat(backend/users): Add get user by ID endpoint and update API docum…
TKanX Jan 7, 2025
67b556d
feat(backend/utils): Add validation functions for limit and offset qu…
TKanX Jan 7, 2025
f01705d
feat(backend/users): Add user safety records endpoint and update API …
TKanX Jan 7, 2025
3186abd
feat(backend/users): Add get settings endpoint and update API documen…
TKanX Jan 7, 2025
fbaa472
fix(backend/models): Ensure settings subdocument does not store `_id`
TKanX Jan 7, 2025
e94e50c
feat(backend/users): Add update username endpoint and update API docu…
TKanX Jan 7, 2025
0a41ed0
fix(backend/routes): Change not found handler to use router middleware
TKanX Jan 7, 2025
2d52a3f
feat(backend/users): Add update email endpoint and update API documen…
TKanX Jan 7, 2025
812679f
feat(backend/users): Add complete email update endpoint and update AP…
TKanX Jan 7, 2025
30978fd
fix(backend/routes): Change email update method from PUT to POST in u…
TKanX Jan 7, 2025
7a554e0
fix(backend/services): Correct documentation for email service
TKanX Jan 7, 2025
2249e9c
feat(backend/users): Add update password endpoint and update API docu…
TKanX Jan 8, 2025
73dd94c
feat(backend/users): Add update profile endpoint and update API docum…
TKanX Jan 8, 2025
5b8cb34
feat(backend/utils): Add avatar size validation to validateAvatar fun…
TKanX Jan 8, 2025
eeabed4
feat(backend/users): Add update settings endpoint and update API docu…
TKanX Jan 9, 2025
3963038
fix(backend/models): Change default user roles to an empty array
TKanX Jan 9, 2025
596ad58
fix(backend/services): Preserve existing settings when updating user …
TKanX Jan 9, 2025
514af58
feat(backend/services): Add updateProfileById function to update user…
TKanX Jan 9, 2025
e5942d0
fix(backend/controllers): Update user profile using updateProfileById…
TKanX Jan 9, 2025
901d64f
refactor(backend/utils): Replace jwtService with jwtUtils for JWT ope…
TKanX Jan 9, 2025
1d998cc
refactor(backend/utils): Move password hashing functions to utils and…
TKanX Jan 9, 2025
57a4001
fix(backend/models): Ensure birthday max date is dynamically calculated
TKanX Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
800 changes: 800 additions & 0 deletions backend/docs/API.md

Large diffs are not rendered by default.

28 changes: 10 additions & 18 deletions backend/src/controllers/authControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

const userService = require('../services/userService');
const emailService = require('../services/emailService');
const jwtService = require('../services/jwtService');

const jwtUtils = require('../utils/jwtUtils');
const validationUtils = require('../utils/validationUtils');

/**
Expand All @@ -23,11 +23,7 @@
}

// Generate a JWT token with the email (for verification)
const token = jwtService.generateToken(
{ email },
process.env.JWT_SECRET,
'1h',
);
const token = jwtUtils.generateToken({ email }, process.env.JWT_SECRET, '1h');

// Send the verification email
try {
Expand Down Expand Up @@ -55,7 +51,7 @@

// Verify JWT token
try {
const payload = jwtService.verifyToken(token, process.env.JWT_SECRET);
const payload = jwtUtils.verifyToken(token, process.env.JWT_SECRET);
if (!payload.email) {
return res.badRequest('Invalid token.', 'INVALID_TOKEN');
}
Expand Down Expand Up @@ -109,7 +105,7 @@
);

return res.success(user, 'User created successfully.');
} catch (error) {

Check warning on line 108 in backend/src/controllers/authControllers.js

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used

Check warning on line 108 in backend/src/controllers/authControllers.js

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used
return res.internalServerError('Error creating user.', 'CREATE_USER_ERROR');
}
};
Expand Down Expand Up @@ -151,12 +147,12 @@
return res.success(
{
user,
refreshToken: jwtService.generateToken(
refreshToken: jwtUtils.generateToken(
{ userId: user._id },
secret,
'30d',
),
accessToken: jwtService.generateToken(
accessToken: jwtUtils.generateToken(
{ userId: user._id },
process.env.JWT_SECRET,
'15m',
Expand Down Expand Up @@ -204,15 +200,15 @@

// Verify the refresh token
try {
const userId = jwtService.decodeToken(refreshTokenBody).userId;
const userId = jwtUtils.decodeToken(refreshTokenBody).userId;
const secret = await userService.getRefreshTokenSecret(
userId,
process.env.JWT_SECRET,
);
jwtService.verifyToken(refreshTokenBody, secret);
jwtUtils.verifyToken(refreshTokenBody, secret);

// Generate a new access token
const accessToken = jwtService.generateToken(
const accessToken = jwtUtils.generateToken(
{ userId },
process.env.JWT_SECRET,
'15m',
Expand Down Expand Up @@ -252,11 +248,7 @@
}

// Generate a JWT token with the email (for verification)
const token = jwtService.generateToken(
{ email },
process.env.JWT_SECRET,
'1h',
);
const token = jwtUtils.generateToken({ email }, process.env.JWT_SECRET, '1h');

// Send the password reset email
try {
Expand Down Expand Up @@ -292,7 +284,7 @@

// Verify JWT token
try {
const payload = jwtService.verifyToken(token, process.env.JWT_SECRET);
const payload = jwtUtils.verifyToken(token, process.env.JWT_SECRET);
if (!payload.email) {
return res.badRequest('Invalid token.', 'INVALID_TOKEN');
}
Expand Down Expand Up @@ -336,7 +328,7 @@
);

return res.success(updatedUser, 'Password reset successfully.');
} catch (error) {

Check warning on line 331 in backend/src/controllers/authControllers.js

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used

Check warning on line 331 in backend/src/controllers/authControllers.js

View workflow job for this annotation

GitHub Actions / Lint

'error' is defined but never used
return res.internalServerError(
'Error resetting password.',
'RESET_PASSWORD_ERROR',
Expand Down
Loading
Loading