Fix: OneTimeLinks (#1719)

* fix otls

* one otl per client

* revert some code

* revert some more code, add comments

* adjust migration
This commit is contained in:
Bernd Storath
2025-03-07 09:16:24 +01:00
committed by GitHub
parent fcb5049dab
commit e5fb6ff3a6
11 changed files with 57 additions and 51 deletions
+16 -8
View File
@@ -5,20 +5,28 @@ export default defineEventHandler(async (event) => {
event,
validateZod(OneTimeLinkGetSchema, event)
);
const clients = await WireGuard.getAllClients();
// TODO: filter on the database level
const client = clients.find(
(client) => client.oneTimeLink?.oneTimeLink === oneTimeLink
);
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 clientId = client.id;
const config = await WireGuard.getClientConfiguration({ clientId });
await Database.oneTimeLinks.erase(clientId);
const config = await WireGuard.getClientConfiguration({
clientId: client.id,
});
await Database.oneTimeLinks.erase(otl.id);
setHeader(
event,
'Content-Disposition',