Added user existence check in userRouteHandler to return 401 status if user is not found, enhancing authentication flow.
Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-03-07 20:32:36 +00:00
parent 5f5eedc798
commit 420ab75467

View File

@ -292,6 +292,10 @@ export const userRouteHandler = async (req, res) => {
if (req.user) {
const authHeader = req.headers.authorization || req.headers.Authorization;
const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
const user = await userModel.findOne({ _id: req.user._id }).lean();
if (!user) {
return res.status(401).json({ error: 'User not found' });
}
return res.json({
access_token: token,
expires_at: req.session?.expiresAt,