Files
wg-easy-ca-lose/src/server/routes/cnf/[oneTimeLink].ts
T
Bernd Storath e5fb6ff3a6 Fix: OneTimeLinks (#1719)
* fix otls

* one otl per client

* revert some code

* revert some more code, add comments

* adjust migration
2025-03-07 09:16:24 +01:00

38 lines
921 B
TypeScript

import { OneTimeLinkGetSchema } from '#db/repositories/oneTimeLink/types';
export default defineEventHandler(async (event) => {
const { oneTimeLink } = await getValidatedRouterParams(
event,
validateZod(OneTimeLinkGetSchema, event)
);
const otl = await Database.oneTimeLinks.getByOtl(oneTimeLink);
if (!otl) {
throw createError({
statusCode: 404,
statusMessage: 'Invalid One Time Link',
});
}
const client = await Database.clients.get(otl.id);
if (!client) {
throw createError({
statusCode: 404,
statusMessage: 'Invalid One Time Link',
});
}
const config = await WireGuard.getClientConfiguration({
clientId: client.id,
});
await Database.oneTimeLinks.erase(otl.id);
setHeader(
event,
'Content-Disposition',
`attachment; filename="${client.name}.conf"`
);
setHeader(event, 'Content-Type', 'text/plain');
return config;
});