octokit-next.js icon indicating copy to clipboard operation
octokit-next.js copied to clipboard

Make the `authStrategy` parameter work with the static `.withDefaults()` method

Open gr2m opened this issue 4 years ago • 2 comments

follow up to #18 and related to #11

What we want is the following

import { Octokit } from "@octokit-next/core";

type CallbackStrategyOptions = {
  callback: () => string | Promise<string>;
};

function createCallbackAuth(options: CallbackStrategyOptions) {
  return async function auth() {
    return options.callback();
  };
}

const OctokitWithCallbackAuth = Octokit.withDefaults({
  authStrategy: createCallbackAuth,
});

// compiler should complain: `{ auth }` should be required because `authStrategy` is set to `createCallbackAuth` by default
new OctokitWithCallbackAuth();

Here is how auth strategies work in Octokit via the authStrategy and auth options: https://github.com/octokit/authentication-strategies.js#authenticationstrategystrategyoptions

gr2m avatar Aug 13 '21 21:08 gr2m

I got some of the necessary work done, but it's not fully working yet, I left a few TODO: comments in the code

https://github.com/octokit/octokit-next.js/blob/af7fdecc699591c4045f9e96b8d1c41869f60703/tests/js/auth/index.test-d.ts#L63-L75

gr2m avatar Sep 14 '22 20:09 gr2m