Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions website/src/pages/api/users/me.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { APIContext } from 'astro';

import { getBackendHost } from '../../../config.ts';
import { getInstanceLogger } from '../../../logger.ts';
import type { ProblemDetail } from '../../../types/ProblemDetail.ts';
import { getErrorLogMessage } from '../../../util/getErrorLogMessage.ts';

const logger = getInstanceLogger('UsersMe');

export async function GET(context: APIContext): Promise<Response> {
const userId = context.locals.gsUserId;

if (userId === undefined) {
const body: ProblemDetail = {
title: 'Unauthorized',
detail: "You're not authorized to access this resource",
status: 401,
instance: context.request.url,
};
return Response.json(body, { status: 401 });
}

try {
const response = await fetch(new URL(`/users/${userId}`, getBackendHost()));
return new Response(response.body, {
status: response.status,
headers: response.headers,
});
Comment thread
fhennig marked this conversation as resolved.
} catch (error) {
Comment on lines +23 to +29
logger.error(getErrorLogMessage(error));
const body: ProblemDetail = {
title: 'Internal Server Error',
detail: 'Failed to connect the backend service',
status: 500,
instance: context.request.url,
};
return Response.json(body, { status: 500 });
}
}
Loading