node-mongo-demo

node.js and mongodb demo

git clone https://9o.is/git/node-mongo-demo.git

commit 33383588211fe32ec6a91d8b4491cb8e63fe1d88
parent 5d347808fb2a50014bccae20bb7cc406f8b4f2fa
Author: Jul <jul@9o.is>
Date:   Sun, 26 Jan 2025 08:09:35 -0500

return 401 in middleware if authorization fails

Diffstat:
Mbackend/src/utils/auth.js | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/backend/src/utils/auth.js b/backend/src/utils/auth.js @@ -16,7 +16,9 @@ const auth = async (req, res, next) => { } next(); - } catch (error) { } + } catch (error) { + res.status(401).json({ message: "Unauthorized" }) + } }; export default auth;