index.js 530 B

1234567891011121314
  1. import { auth } from "./auth";
  2. import { hook } from "./hook";
  3. export const createTokenAuth = function createTokenAuth(token) {
  4. if (!token) {
  5. throw new Error("[@octokit/auth-token] No token passed to createTokenAuth");
  6. }
  7. if (typeof token !== "string") {
  8. throw new Error("[@octokit/auth-token] Token passed to createTokenAuth is not a string");
  9. }
  10. token = token.replace(/^(token|bearer) +/i, "");
  11. return Object.assign(auth.bind(null, token), {
  12. hook: hook.bind(null, token),
  13. });
  14. };