style: add eslint and prettier

This commit is contained in:
Cfp
2025-06-22 17:06:50 +02:00
parent 6eb465d43a
commit 6ecaef6e8b
11 changed files with 552 additions and 214 deletions

View File

@ -3,19 +3,27 @@ import jwkToPem, { type JWK } from "jwk-to-pem";
const JWKS = process.env.OIDC_JWKS_URL || "";
type JWKSResponse = {
keys: Array<{ kid: string; kty: string; use: string; alg: Algorithm; n: string; e: string }>;
interface JWKSResponse {
keys: {
kid: string;
kty: string;
use: string;
alg: Algorithm;
n: string;
e: string;
}[];
}
export async function verifyToken(token: string): Promise<boolean> {
const decoded = decode(token, { complete: true });
const jwks = await fetch(JWKS)
.then(res => res.json() as Promise<JWKSResponse>);
const jwks = await fetch(JWKS).then(
(res) => res.json() as Promise<JWKSResponse>,
);
if (!decoded || !decoded.header || !decoded.header.kid) {
return false;
}
const key = jwks.keys.find(k => k.kid === decoded.header.kid);
const key = jwks.keys.find((k) => k.kid === decoded.header.kid);
if (!key) {
return false;
}
@ -24,7 +32,7 @@ export async function verifyToken(token: string): Promise<boolean> {
const res = verify(token, pem, { algorithms: [key.alg] });
console.log(res);
return typeof res === "object" && "sub" in res;
} catch (err) {
} catch (_err) {
return false;
}
}