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

Using Dashport as a middleware leads to compile error #44

Open
finlaydotb opened this issue Apr 3, 2021 · 12 comments
Open

Using Dashport as a middleware leads to compile error #44

finlaydotb opened this issue Apr 3, 2021 · 12 comments

Comments

@finlaydotb
Copy link

finlaydotb commented Apr 3, 2021

Hi there 👋

First all, thanks for making this library. Looks like the perfect thing I need for my use case. The only problem now is that I am following the documentation and it does not seem to work. In the documentation you see the following lines:

Dashport is now ready to authenticate. Dashport's authenticate method acts as middleware, so it can be used like so

import { dashport, googStrat, serializerA, deserializerA } from './dashportConfig.ts';

const xx = async (ctx: any, next: any) => {
    ctx.response.body = 'This is a private page!';
}

router.get('/privatepage', dashport.authenticate(googStrat, serializerA, deserializerA), xx)

But if I do so, I get the following compilation error

  Overload 1 of 2, '(name: string, path: string, ...middleware: RouterMiddleware<RouteParams, Record<string, any>>[]): Router<RouteParams, Record<string, any>>', gave the following error.
    Argument of type '(ctx: any, next: any) => Promise<void>' is not assignable to parameter of type 'string'.  Overload 2 of 2, '(path: string, ...middleware: RouterMiddleware<RouteParams, Record<string, any>>[]): Router<RouteParams, Record<string, any>>', gave the following error.
    Argument of type 'Function' is not assignable to parameter of type 'RouterMiddleware<RouteParams, Record<string, any>>'.
      Type 'Function' provides no match for the signature '(context: RouterContext<RouteParams, Record<string, any>>, next: () => Promise<void>): void | Promise<void>'.
router.get('/privatepage', xx, dashport.authenticate(googStrat, serializerA, deserializerA))

Any ideas what could be going wrong? Thanks!

@finlaydotb finlaydotb changed the title Using Dashport as a middleware leads to compile error :( Using Dashport as a middleware leads to compile error Apr 9, 2021
@BAlexanderNance
Copy link
Contributor

Hey, sorry this response is so delayed, things can get hectic. I am not sure if this remedies your issue, but I looked into it and seemed to have issues with deno.land not serving the most recent version if you do not specify. I would recommend trying to just import V1.2.0 and see if you have any progress. if not I am happy to take a closer look at your code and figure out is triggering this bug with dashport.

-Alex

@finlaydotb
Copy link
Author

Unfortunately the issue still persist:

error: TS2769 [ERROR]: No overload matches this call.
  Overload 1 of 2, '(name: string, path: string, ...middleware: RouterMiddleware<RouteParams, Record<string, any>>[]): Router<RouteParams, Record<string, any>>', gave the following error.
    Argument of type 'Function' is not assignable to parameter of type 'string'.  Overload 2 of 2, '(path: string, ...middleware: RouterMiddleware<RouteParams, Record<string, any>>[]): Router<RouteParams, Record<string, any>>', gave the following error.
    Argument of type 'Function' is not assignable to parameter of type 'RouterMiddleware<RouteParams, Record<string, any>>'.
      Type 'Function' provides no match for the signature '(context: RouterContext<RouteParams, Record<string, any>>, next: () => Promise<void>): void | Promise<void>'.
    dashport.authenticate(googStrat, serializerA, deserializerA),

The imports I am using are:

import { DashportOak } from 'https://deno.land/x/dashport@v1.2.0/mod.ts';
import GoogleStrategy from 'https://deno.land/x/dashport_google@v1.0.0/mod.ts'

@royletron
Copy link

royletron commented Apr 20, 2021

@finlaydotb I had the same issue, but it looks like it's a typescript definitions mismatch between what Oak wants and what Dashport gives. I can't dig too much deeper but the following worked for me:

import {
  Application,
  Router,
  RouterMiddleware,
} from "https://deno.land/x/oak/mod.ts";
...

router.get(
  "/auth/google",
  dashport.authenticate(
    googleStrat,
    serializer,
    deserializer
  ) as RouterMiddleware
);

@sportelance
Copy link
Contributor

sportelance commented Apr 21, 2021

Hey Finlay! Sorry for the delay. I'm having trouble replicating your specific issue. What other info could you give me about your setup?
I did hit a different error because the version of Oak I was using was out of date, so I'd check that if you haven't already.
If triple checking that your versions are all up to date doesn't work, please reach back out.

@finlaydotb
Copy link
Author

Hey @sportelance sorry also for the late response. Strangely enough @royletron suggestion to type cast to RouterMiddleware seems to have fixed the compilation error. I am not sure why this is the case, but right now at least introducing Dashport does not cause the project to stop compiling...next is to see if it actually does what it should do :)

@finlaydotb
Copy link
Author

I'll keep this issue open as I am not sure manually casting to RouterMiddleware is the way to go

@finlaydotb
Copy link
Author

finlaydotb commented May 11, 2021

Okay, upgraded my version of deno ( 1.9.2) and oak (7.4.0), and the as RouterMiddleware type cast trick is no longer working :(

Any insight on this issue? and is there a recommended version of oak to use with each corresponding dashport version? Could not see any version matrix in the readme.

Update: oak version 6.5.0 seems to be the oldest version in which the as RouterMiddleware trick works

@dadepo
Copy link

dadepo commented May 18, 2021

I am also facing the same issue. Getting error: TS2769 [ERROR]: No overload matches this call compilation failure.

@sportelance
Copy link
Contributor

Hey guys,
6.5.0 is the latest version of Oak that the module is currently working with. Oak has made many, many changes since our initial release and every type change they make affects the functionality of the module. This is clearly a problem in need of a solution and we're working on it.
In the meantime, I think Dashport, unfortunately, will need to be run with Oak 6.5.0

@finlaydotb
Copy link
Author

@sportelance thanks for the update. I'll stick with Oak 6.5.0 even though I still need to have the as RouterMiddleware type assertion to get compilation to work. Better than not having a working application at all :)

This is clearly a problem in need of a solution and we're working on it.

Godspeed!

Thanks!

@dannyob
Copy link

dannyob commented Nov 18, 2021

I'm now getting

error: TS2345 [ERROR]: Argument of type 'import("https://deno.land/x/oak@v6.5.0/application.ts").Application<Record<string, any>>' is not assignable to parameter of type 'import("https://deno.land/x/oak@v10.0.0/application.ts").Application<Record<string, any>>'.
  Type 'Application<Record<string, any>>' is missing the following properties from type 'Application<Record<string, any>>': #contextState, #middleware, #serverConstructor, #getComposed, and 3 more.
const dashport = new DashportOak(app)

which I /think/ means that DashportOak is expecting the latest version of Oak, even though it does not work with it? (Apologies if that's wrong, I'm pretty new to Deno)

@robertheessels
Copy link

dashport.authenticate(googStrat, serializerA, deserializerA) as any works for me with the newest oak and dashport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants