Shopify / koa-shopify-auth

DEPRECATED Middleware to authenticate a Koa application with Shopify
MIT License
80 stars 64 forks source link

shopifyAuth typescript types are not aligned #117

Closed coler-j closed 3 years ago

coler-j commented 3 years ago

Readme shows:

app.use(
  shopifyAuth({
    // if specified, mounts the routes off of the given path
    // eg. /shopify/auth, /shopify/auth/callback
    // defaults to ''
    prefix: '/shopify',
    // set access mode, default is 'online'
    accessMode: 'offline',
    // callback for when auth is completed
    afterAuth(ctx) {
      const { shop, accessToken } = ctx.state.shopify;

      console.log('We did it!', accessToken);

      ctx.redirect('/');
    },
  }),
);

But actual ts interface for shopifyAuth is:

export interface AuthConfig {
    secret: string;
    apiKey: string;
    myShopifyDomain?: string;
    accessMode?: 'online' | 'offline';
    afterAuth?(ctx: Context): void;
}
export interface OAuthStartOptions extends AuthConfig {
    prefix?: string;
    scopes?: string[];
}

export default function createShopifyAuth(options: OAuthStartOptions): (ctx: Context, next: NextFunction) => Promise<void>;

As you can see there are many required properties in AuthConfig which are not shown in the example. Is there some magic that fills these values in? If so, that doesn't seem to align with the typescript compiler as these properties are required.

Leads to errors like:

Argument of type '{ afterAuth(ctx: Context): Promise; }' is not assignable to parameter of type 'OAuthStartOptions'. Type '{ afterAuth(ctx: Context): Promise; }' is missing the following properties from type 'OAuthStartOptions': secret, apiKey

coler-j commented 3 years ago

I think my local node_modules was in a bad state. Deleted it, and re-installed latest and the types became correct.