UNPKG

@foal/jwt

Version:

Authentication with JWT for FoalTS

21 lines (20 loc) 791 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSecretOrPublicKey = getSecretOrPublicKey; const core_1 = require("@foal/core"); function getSecretOrPublicKey() { const secret = core_1.Config.get('settings.jwt.secret', 'string'); if (secret) { const secretEncoding = core_1.Config.get('settings.jwt.secretEncoding', 'string'); if (secretEncoding) { return Buffer.from(secret, secretEncoding); } return secret; } const publicKey = core_1.Config.get('settings.jwt.publicKey', 'string'); if (publicKey) { return publicKey; } throw new Error('[CONFIG] You must provide at least one of these configuration keys: ' + 'settings.jwt.secret or settings.jwt.publicKey.'); }