Skip to content

Commit 44579e1

Browse files
committed
change unactive http status
1 parent 9811544 commit 44579e1

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Diff for: api/src/models/utils/findAndGenerateToken.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@ async function findAndGenerateToken (payload, from) {
1010
if (!email) throw new APIError('Email must be provided for login')
1111
let user
1212

13-
if (from === 'admin') {
14-
user = await Admin.findOne({ email }).exec()
15-
}
16-
if (from === 'user') {
17-
user = await User.findOne({ email }).exec()
18-
}
13+
if (from === 'admin') user = await Admin.findOne({ email }).exec()
14+
if (from === 'user') user = await User.findOne({ email }).exec()
1915

2016
if (!user) throw new APIError(`No user associated with ${email}`, httpStatus.NOT_FOUND)
2117

2218
const passwordOK = await user.passwordMatches(password)
2319

2420
if (!passwordOK) throw new APIError(`Password mismatch`, httpStatus.UNAUTHORIZED)
2521
if (from === 'user' && !user.active) {
26-
throw new APIError(`User not activated`, httpStatus.UNAUTHORIZED)
22+
throw new APIError(`User not activated`, httpStatus.FORBIDDEN)
2723
}
2824

2925
return user

0 commit comments

Comments
 (0)