UNPKG

@whook/example

Version:
43 lines (32 loc) 975 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _knifecycle = require("knifecycle"); var _yerror = _interopRequireDefault(require("yerror")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _default = (0, _knifecycle.service)(initAuthentication, "authentication", ["TOKEN"]); // A fake authentication service exports.default = _default; async function initAuthentication({ TOKEN }) { const authentication = { check: async (type, data) => { if (type === 'fake') { return data; } if (type === 'bearer') { if (data.hash === TOKEN) { return { userId: 1, scopes: ['admin'] }; } throw new _yerror.default('E_BAD_BEARER_TOKEN', type, data.hash); } throw new _yerror.default('E_UNEXPECTED_AUTH_TYPE', type); } }; return authentication; }