Skip to content

Commit 1c352f3

Browse files
committed
fix: auth guard unhandling issue when token without bearer
1 parent a9913df commit 1c352f3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/app/middlewares/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const auth =
1414
throw new ApiError(StatusCodes.UNAUTHORIZED, 'You are not authorized');
1515
}
1616

17-
if (tokenWithBearer && tokenWithBearer.startsWith('Bearer')) {
17+
if (tokenWithBearer.startsWith('Bearer')) {
1818
const token = tokenWithBearer.split(' ')[1];
1919

2020
//verify token
@@ -34,6 +34,8 @@ const auth =
3434
}
3535

3636
next();
37+
} else {
38+
throw new ApiError(StatusCodes.UNAUTHORIZED, 'You are not authorized');
3739
}
3840
} catch (error) {
3941
next(error);

0 commit comments

Comments
 (0)