From 6d6596137feda3027f918227b6ed5df69cc01847 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Mon, 18 Nov 2024 10:40:54 +0100 Subject: [PATCH] add avatar endpoint --- backend/src/routes/avatar.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 backend/src/routes/avatar.ts diff --git a/backend/src/routes/avatar.ts b/backend/src/routes/avatar.ts new file mode 100644 index 0000000..2f9c1df --- /dev/null +++ b/backend/src/routes/avatar.ts @@ -0,0 +1,21 @@ +import express, {Request, Response} from 'express'; +import UserMetadata from 'supertokens-node/recipe/usermetadata'; +import {logger} from '../utilities/logger'; + +const router = express.Router(); + +router.get('/avatar', async (req: Request, res: Response) => { + logger.debug('api avatar route hit'); + // @ts-ignore + const session = req.session; + const userId = session.getUserId(); + const {metadata} = await UserMetadata.getUserMetadata(userId); + const avatarUrl = metadata.avatarUrl; + if (avatarUrl) { + res.json({avatarUrl: avatarUrl}); + } else { + res.json({avatarUrl: null}); + } +}); + +export default router;