mxstbr / passport-magic-login

Passwordless authentication with magic links for Passport.js.
MIT License
664 stars 45 forks source link

feat: remove next/express dep #2

Closed maraisr closed 3 years ago

maraisr commented 3 years ago

This removes the next "dev dep", that would caused non next users typing to fail, or for those not using express having potentially incompatible typing.

This I believe is a phase 1 of 2, seeing as both Express and Next extend the native http interface we could simply just do away with their magic wrapper methods, like json and redirect and implement those ourselves, meaning server's like Polka could also make use of this, and not have to expose those methods.

Here is an image proving typings still work: image

mxstbr commented 3 years ago

This errors on the passport.use call now 😢 Any ideas how to fix this?

error TS2345: Argument of type 'MagicLoginStrategy' is not assignable to parameter of type 'Strategy'.
  Types of property 'authenticate' are incompatible.
    Type '(req: Request) => void' is not assignable to type '(this: StrategyCreated<Strategy, Strategy & StrategyCreatedStatic>, req: Request<ParamsDictionary, any, any, ParsedQs>, options?: any) => any'.
      Types of parameters 'req' and 'req' are incompatible.
        Type 'Request<ParamsDictionary, any, any, ParsedQs>' is not assignable to type 'Request'.
          Types of property 'query' are incompatible.
            Type 'ParsedQs' is not assignable to type 'Record<string, string | string[]>'.
              Index signatures are incompatible.
                Type 'string | string[] | ParsedQs | ParsedQs[] | undefined' is not assignable to type 'string | string[]'.
                  Type 'undefined' is not assignable to type 'string | string[]'.

13 passport.use(magicLink);
                ~~~~~~~~~
maraisr commented 3 years ago

I can take a look at this. I think its the Record, which isnt quite compat with an object. I think i may need to make query be any, and not type it as strongly. Ill send up another PR shortly.

Further that, can you tell me why you're using util's inherit method, and not just a class extend?