UNPKG

mappersmith

Version:

It is a lightweight rest client for node.js and the browser

1 lines 1.24 kB
{"version":3,"sources":["../../../src/middleware/basic-auth.ts"],"sourcesContent":["import type { Auth } from '../types'\nimport type { Middleware } from './index'\nimport { assign } from '../utils/index'\n\n/**\n * Automatically configure your requests with basic auth\n *\n * Example:\n * In your manifest:\n * {\n * middleware: [ BasicAuthMiddleware({ username: 'bob', password: 'bob' }) ]\n * }\n *\n * Making the call:\n * client.User.all()\n * // => header: \"Authorization: Basic Ym9iOmJvYg==\"\n */\nexport const BasicAuthMiddleware = (authConfig: Auth): Middleware =>\n function BasicAuthMiddleware() {\n return {\n async prepareRequest(next) {\n const request = await next()\n const auth = request.auth()\n return !auth // Keep the override\n ? request.enhance({ auth: assign({}, authConfig) })\n : request\n },\n }\n }\nexport default BasicAuthMiddleware\n"],"mappings":";AAEA,SAAS,cAAc;AAehB,IAAM,sBAAsB,CAAC,eAClC,SAASA,uBAAsB;AAC7B,SAAO;AAAA,IACL,MAAM,eAAe,MAAM;AACzB,YAAM,UAAU,MAAM,KAAK;AAC3B,YAAM,OAAO,QAAQ,KAAK;AAC1B,aAAO,CAAC,OACJ,QAAQ,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,UAAU,EAAE,CAAC,IAChD;AAAA,IACN;AAAA,EACF;AACF;AACF,IAAO,qBAAQ;","names":["BasicAuthMiddleware"]}