Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gr2m opened this issue Aug 13, 2021 · 2 comments · Fixed by #21
Open

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

gr2m opened this issue Aug 13, 2021 · 2 comments · Fixed by #21
Labels
Type: Bug Something isn't working as documented typescript
Projects

Comments

@gr2m
Copy link
Contributor

gr2m commented Aug 13, 2021

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
Copy link
Contributor Author

gr2m commented Sep 14, 2022

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

// Note: The code above gets the constructor options type from
// `new <NowProvided>(...options: RequiredIfRemaining<PredefinedOptions, NowProvided>)`
// while the code below gets the type from Octokit.constructor options
// TODO: @ts-expect-error - options is required
new OctokitWithCallbackAuth();
// TODO: @ts-expect-error - options.auth is required
new OctokitWithCallbackAuth({});
// TODO: @ts-expect-error - options.auth must be set to `{ callback }`
new OctokitWithCallbackAuth({
auth: "",
});

@gr2m gr2m reopened this Sep 14, 2022
@ghost ghost moved this from Done to Inbox in JS Sep 14, 2022
@gr2m gr2m added the Type: Bug Something isn't working as documented label Sep 14, 2022
@ghost ghost moved this from Inbox to Bugs in JS Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented typescript
Projects
No open projects
JS
  
Bugs
Development

Successfully merging a pull request may close this issue.

1 participant