mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-27 23:13:01 -04:00
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import SQL from 'sql-template-strings';
|
|
|
|
import { filterObjectKeys, PermissionAreas } from '#shared/helpers.ts';
|
|
import type { Authenticator } from '#shared/user.ts';
|
|
import type { AuthenticatorRow } from '~~/server/express/user.ts';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { isGranted } = await useAuthentication(event);
|
|
if (!isGranted(PermissionAreas.Community) && !isGranted(PermissionAreas.Superuser)) {
|
|
throw createError({
|
|
status: 401,
|
|
statusMessage: 'Unauthorised',
|
|
});
|
|
}
|
|
|
|
const db = useDatabase();
|
|
const id = getRouterParam(event, 'id');
|
|
return (await db.all<AuthenticatorRow>(SQL`
|
|
SELECT * FROM authenticators
|
|
WHERE userId = ${id}
|
|
ORDER BY id DESC
|
|
`)).map((authenticatorRow): Omit<Authenticator, 'userId'> => {
|
|
const payload = JSON.parse(authenticatorRow.payload);
|
|
return {
|
|
id: authenticatorRow.id,
|
|
type: authenticatorRow.type,
|
|
payload: typeof payload === 'string'
|
|
? ''
|
|
: filterObjectKeys(payload, ['id', 'email', 'name', 'instance', 'username']),
|
|
validUntil: authenticatorRow.validUntil,
|
|
};
|
|
});
|
|
});
|