add better access control

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-05 23:47:45 +02:00
parent 68c4530ea5
commit 1e6cd0dee2
17 changed files with 309 additions and 34 deletions

View File

@@ -1,4 +1,5 @@
import type { RawRequestDefaultExpression } from 'fastify';
import jwt from 'jsonwebtoken';
import { verifyPassword } from '@openpanel/common';
import type { IServiceClient } from '@openpanel/db';
@@ -103,3 +104,23 @@ export async function validateExportRequest(
return client;
}
export function validateClerkJwt(token?: string) {
if (!token) {
return null;
}
try {
const decoded = jwt.verify(
token,
process.env.CLERK_PUBLIC_PEM_KEY!.replace(/\\n/g, '\n')
);
if (typeof decoded === 'object') {
return decoded;
}
} catch (e) {
//
}
return null;
}