This commit is contained in:
Konstantin Wohlwend 2024-12-01 01:58:52 -08:00
parent 1b84d27430
commit a94907112d

View File

@ -48,9 +48,14 @@ function createAdapter(options: {
}
async upsert(id: string, payload: AdapterPayload, expiresInSeconds: number): Promise<void> {
if (expiresInSeconds < 0) throw new StackAssertionError(`expiresInSeconds must be non-negative, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (expiresInSeconds > 60 * 60 * 24 * 365 * 100) throw new StackAssertionError(`expiresInSeconds must be less than 100 years, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (!Number.isFinite(expiresInSeconds)) throw new StackAssertionError(`expiresInSeconds must be a finite number, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
try {
if (expiresInSeconds < 0) throw new StackAssertionError(`expiresInSeconds of ${this.model}:${id} must be non-negative, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (expiresInSeconds > 60 * 60 * 24 * 365 * 100) throw new StackAssertionError(`expiresInSeconds of ${this.model}:${id} must be less than 100 years, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
if (!Number.isFinite(expiresInSeconds)) throw new StackAssertionError(`expiresInSeconds of ${this.model}:${id} must be a finite number, got ${expiresInSeconds}`, { expiresInSeconds, model: this.model, id, payload });
} catch (err) {
captureError('idp-adapter-upsert-assertion-error', err);
expiresInSeconds = 60 * 60 * 60 * 24;
}
await niceUpdate(this.model, id, () => ({ payload, expiresAt: new Date(Date.now() + expiresInSeconds * 1000) }));
}
@ -220,10 +225,10 @@ export async function createOidcProvider(options: { id: string, baseUrl: string
captureError('idp-oidc-provider-server-error', err);
});
function middleware(middleware: Parameters<typeof oidc.use>[0]) {
function middleware(mw: Parameters<typeof oidc.use>[0]) {
oidc.use((ctx, next) => {
try {
return middleware(ctx, next);
return mw(ctx, next);
} catch (err) {
captureError('idp-oidc-provider-middleware-error', err);
throw err;