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
Some checks failed
farmcontrol/farmcontrol-api/pipeline/head There was a failure building this commit
This commit is contained in:
parent
5f5eedc798
commit
420ab75467
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user