import { meJson } from '../../auth/meJson.js'; /** * Registers the current-user route (requires prior auth middleware populating `req.user`). * @param {import('express').Application} app - Express app * @param {string} [basePath=''] - Optional URL prefix for all routes in this module */ export function register(app, basePath = '') { /** * @openapi * /auth/me: * get: * tags: [Auth] * summary: Current user * description: Returns the authenticated user from the session cookie and the Google client ID. Unauthenticated calls still receive `googleClientId` with 401. * security: * - cookieAuth: [] * x-markdown: auth/me.md * responses: * 200: * description: Authenticated * content: * application/json: * schema: * type: object * properties: * user: * $ref: '#/components/schemas/User' * googleClientId: * type: string * 401: * description: Unauthorized — still includes `googleClientId` for the frontend * content: * application/json: * schema: * type: object * properties: * error: * type: string * googleClientId: * type: string */ app.get(`${basePath}/auth/me`, (req, res) => { const { id, email, selectedCompanyId, picture } = req.user; const user = { id, email, selectedCompanyId, ...(picture && { picture }) }; meJson(res, 200, { user }); }); }