autonomous.contact/public/api/users/me/index.ts

20 lines
779 B
TypeScript
Raw Normal View History

import * as CANNED_RESPONSES from '../../../../utils/canned_responses.ts';
2025-06-25 20:51:29 -07:00
import { get_session, get_user, PRECHECK_TABLE, require_user } from '../../../../utils/prechecks.ts';
export const PERMISSIONS: Record<string, (req: Request, meta: Record<string, any>) => Promise<boolean>> = {};
export const PRECHECKS: PRECHECK_TABLE = {};
// GET /api/users/me - Get the current user
PRECHECKS.GET = [get_session, get_user, require_user, (_req: Request, meta: Record<string, any>): Response | undefined => {
const can_read_self = meta.user?.permissions.includes('self.read');
2025-06-25 20:51:29 -07:00
if (!can_read_self) {
2025-06-25 20:51:29 -07:00
return CANNED_RESPONSES.permission_denied();
}
}];
export function GET(_req: Request, meta: Record<string, any>): Response {
return Response.json(meta.user, {
status: 200
});
}