question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Dashport as a middleware leads to compile error

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sportelancecommented, May 19, 2021

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

1reaction
royletroncommented, 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
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Router.use() requires middleware function but got a Object ...
I was getting the same error message but had a different issue. Posting for others that are stuck on same.
Read more >
How To Implement Custom Error Responses in Express - Auth0
Let's see what you need to get started with error response customization for 401 Unauthorized and 403 Forbidden errors in Express. An ...
Read more >
Express.js Error Handling 101 - ButterCMS
Set up error handling middleware for operational errors: In an Express application, it is essential to have all your error handlers in a ......
Read more >
Understanding Vue middleware pipelines - LogRocket Blog
For example, let's say we have a dashboard route that can only be accessed by authenticated users, we can make use of an...
Read more >
Advanced Features: Middleware - Next.js
Learn how to use Middleware to run code before a request is completed. ... values need to be constants so they can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found