@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
35 lines • 1.49 kB
JavaScript
// packages/core/src/auth/dashboard-auth-config.ts
import { durationToMs } from '../config/parse-duration.js';
const DEFAULT_TTL = '8h';
/**
* Validate + resolve `dashboardAuth`. Returns `null` when unconfigured (behavior
* unchanged). Throws at boot (fail closed) when configured but missing a secret
* or any hook — the host learns immediately rather than shipping an open or
* un-mintable dashboard.
*/
export function resolveDashboardAuth(options) {
if (options === undefined)
return null;
if (typeof options.secret !== 'string' || options.secret === '') {
throw new Error('Telescope dashboardAuth: `secret` is required and must be a non-empty string ' +
'(HMAC-SHA256 signing key, 32+ bytes recommended). Failing closed.');
}
const modes = [];
if (options.session !== undefined)
modes.push('session');
if (options.login !== undefined)
modes.push('login');
if (modes.length === 0) {
throw new Error('Telescope dashboardAuth: at least one of `session` or `login` must be ' +
'provided (otherwise the cookie can never be minted).');
}
const ttlMs = durationToMs(options.ttl ?? DEFAULT_TTL);
return {
secret: options.secret,
ttlMs,
modes,
...(options.session !== undefined ? { session: options.session } : {}),
...(options.login !== undefined ? { login: options.login } : {}),
};
}
//# sourceMappingURL=dashboard-auth-config.js.map