Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 1 addition & 8 deletions server/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,24 @@ export const checkSession = async (req, res) => {
export const loginLocal = async (req, res, next) => {
if (req.sanitizedErrors) {
return res.status(422).json({
success: false,
message: 'Analysis could not be created due to validation errors',
errors: req.sanitizedErrors,
});
}

return passport.authenticate('local', (err, user /* , info */) => {
if (err) {
return res.status(500).json({
success: false,
message: 'An error occurred during login',
});
return next(err);
}

if (!user) { //* Will trigger if user does not exist
return res.status(401).json({
success: false,
message: 'The combination of email and password is incorrect',
});
}

if (user.role === 'participant') {
return res.status(403).json({
success: false,
message: 'Participant login is disabled',
});
}
Expand All @@ -215,7 +209,6 @@ export const loginLocal = async (req, res, next) => {
updateUserLastLoginDate(user.id); // Fire-and-forget function

return res.status(200).json({
success: true,
message: 'Login successful',
user: {
id: user.id,
Expand Down
18 changes: 10 additions & 8 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ paths:
schema:
type: object
properties:
success:
$ref: "#/components/schemas/SuccessTrueStatus"
message:
type: string
example: Login successful
Expand All @@ -477,21 +475,27 @@ paths:
schema:
type: object
properties:
success:
$ref: "#/components/schemas/SuccessFalseStatus"
message:
type: string
example: The combination of email and password is incorrect

403:
description: Participant login is disabled
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Participant login is disabled
422:
description: Validation error
content:
application/json:
schema:
type: object
properties:
success:
$ref: "#/components/schemas/SuccessFalseStatus"
message:
type: string
example: User could not be created due to validation errors
Expand All @@ -507,8 +511,6 @@ paths:
schema:
type: object
properties:
success:
$ref: "#/components/schemas/SuccessFalseStatus"
message:
$ref: '#/components/schemas/InternalErrorMessage'

Expand Down