Skip to content

Commit e8dcb59

Browse files
committed
add jsdocs to userController.authManagement routes
1 parent 6332a45 commit e8dcb59

1 file changed

Lines changed: 62 additions & 7 deletions

File tree

server/controllers/user.controller/authManagement.ts

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ import {
99
PublicUserOrError,
1010
ResetPasswordInitiateRequestBody,
1111
ResetOrUpdatePasswordRequestParams,
12-
UpdatePasswordRequestBody
12+
UpdatePasswordRequestBody,
13+
UpdateSettingsRequestBody
1314
} from '../../types';
1415
import { mailerService } from '../../utils/mail';
1516
import { renderResetPassword, renderEmailConfirmation } from '../../views/mail';
1617

18+
/**
19+
* - Method: `POST`
20+
* - Endpoint: `/reset-password`
21+
* - Authenticated: `false`
22+
* - Id: `UserController.resetPasswordInitiate`
23+
*
24+
* Description:
25+
* - Send an Reset Email email to the registered email account
26+
*/
1727
export const resetPasswordInitiate: RequestHandler<
1828
{},
1929
GenericResponseBody,
@@ -58,6 +68,17 @@ export const resetPasswordInitiate: RequestHandler<
5868
}
5969
};
6070

71+
/**
72+
* - Method: `GET`
73+
* - Endpoint: `/reset-password/:token`
74+
* - Authenticated: `false`
75+
* - Id: `UserController.validateResetPasswordToken`
76+
*
77+
* Description:
78+
* - The link in the Reset Password email, which contains a reset token that is valid for 1h
79+
* - If valid, the user will see a form to reset their password
80+
* - Else they will see a message that their token has expired
81+
*/
6182
export const validateResetPasswordToken: RequestHandler<
6283
ResetOrUpdatePasswordRequestParams,
6384
GenericResponseBody
@@ -76,6 +97,18 @@ export const validateResetPasswordToken: RequestHandler<
7697
res.json({ success: true });
7798
};
7899

100+
/**
101+
* - Method: `POST`
102+
* - Endpoint: `/reset-password/:token`
103+
* - Authenticated: `false`
104+
* - Id: `UserController.updatePassword`
105+
*
106+
* Description:
107+
* - Used by the new password form to update a user's password with the valid token
108+
* - Returns a Generic 401 - 'Password reset token is invalid or has expired.' if the token timed out
109+
* - Returns a PublicUser if successfully saved
110+
* - Returns an Error if network error on save attempt
111+
*/
79112
export const updatePassword: RequestHandler<
80113
ResetOrUpdatePasswordRequestParams,
81114
PublicUserOrErrorOrGeneric,
@@ -102,15 +135,19 @@ export const updatePassword: RequestHandler<
102135
// eventually send email that the password has been reset
103136
};
104137

138+
/**
139+
* - Method: `PUT`
140+
* - Endpoint: `/account`
141+
* - Authenticated: `true`
142+
* - Id: `UserController.updateSettings`
143+
*
144+
* Description:
145+
* - Used to update the user's username, email, or password while authenticated
146+
*/
105147
export const updateSettings: RequestHandler<
106148
{},
107149
PublicUserOrError,
108-
{
109-
username: string;
110-
email: string;
111-
newPassword?: string;
112-
currentPassword?: string;
113-
}
150+
UpdateSettingsRequestBody
114151
> = async (req, res) => {
115152
try {
116153
const user = await User.findById(req.user!.id);
@@ -168,6 +205,15 @@ export const updateSettings: RequestHandler<
168205
}
169206
};
170207

208+
/**
209+
* - Method: `DELETE`
210+
* - Endpoint: `/auth/github`
211+
* - Authenticated: `false` -- TODO: update to true?
212+
* - Id: `UserController.unlinkGithub`
213+
*
214+
* Description:
215+
* - Unlink github account
216+
*/
171217
export const unlinkGithub: RequestHandler<
172218
{},
173219
UnlinkThirdPartyResponseBody
@@ -186,6 +232,15 @@ export const unlinkGithub: RequestHandler<
186232
});
187233
};
188234

235+
/**
236+
* - Method: `DELETE`
237+
* - Endpoint: `/auth/google`
238+
* - Authenticated: `false` -- TODO: update to true?
239+
* - Id: `UserController.unlinkGoogle`
240+
*
241+
* Description:
242+
* - Unlink google account
243+
*/
189244
export const unlinkGoogle: RequestHandler<
190245
{},
191246
UnlinkThirdPartyResponseBody

0 commit comments

Comments
 (0)