This commit is contained in:
seb
2026-10-29 16:27:02 +01:00
parent 005b48ff66
commit 676a40d4fe
6 changed files with 50 additions and 16 deletions

View File

@@ -17,7 +17,7 @@ export function register(app, basePath = '') {
* description: |
* Returns the authenticated user from the session cookie and the Google client ID.
* `user.picture` is the stored profile image as a base64 string when present.
* Unauthenticated calls still receive `googleClientId` with 401.
* Unauthenticated calls still receive `googleClientId` and `schemaVersion` with 401.
* security:
* - cookieAuth: []
* x-markdown: auth/me.md
@@ -33,8 +33,11 @@ export function register(app, basePath = '') {
* $ref: '#/components/schemas/User'
* googleClientId:
* type: string
* schemaVersion:
* type: integer
* description: Current database schema version
* 401:
* description: Unauthorized — still includes `googleClientId` for the frontend
* description: Unauthorized — still includes `googleClientId` and `schemaVersion` for the frontend
* content:
* application/json:
* schema:
@@ -44,12 +47,15 @@ export function register(app, basePath = '') {
* type: string
* googleClientId:
* type: string
* schemaVersion:
* type: integer
* description: Current database schema version
*/
app.get(`${basePath}/auth/me`, async (req, res) => {
try {
const row = await db.getById(req.user.id);
if (!row) {
return respondWithAuthenticatedUser(res, 403, { error: 'User is no longer authorized' });
return await respondWithAuthenticatedUser(res, 403, { error: 'User is no longer authorized' });
}
const pictureBinary = toPictureBuffer(row.pictureBinary);
@@ -59,10 +65,10 @@ export function register(app, basePath = '') {
selectedCompanyId: row.selectedCompanyId,
...(pictureBinary && { picture: pictureBinary.toString('base64') }),
};
respondWithAuthenticatedUser(res, 200, { user });
await respondWithAuthenticatedUser(res, 200, { user });
} catch (error) {
console.error('Get current user failed:', error);
respondWithAuthenticatedUser(res, 500, { error: 'Failed to load user' });
await respondWithAuthenticatedUser(res, 500, { error: 'Failed to load user' });
}
});
}