From 29f92cd0940c2036a5da76676575e895f13a4641 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Mon, 23 Sep 2024 23:55:53 +0530 Subject: [PATCH] feat: get current user --- server/src/routes/auth.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 6c2dd58c..dabd4855 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -71,3 +71,12 @@ const logout = async (req, res) => { res.status(500).send(`Could not logout user - ${error.message}`) } } + +const currentUser = async (req, res) => { + try { + const user = await User.findById(req.user._id).select('-password').exec(); + return res.status(200).json({ ok: true }); + } catch (error) { + return res.status(500).send(`Could not fetch current user : ${error.message}.`); + } +}; \ No newline at end of file