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

Authenticated as class decorator bug #467

Closed
d0whc3r opened this issue Oct 13, 2018 · 4 comments
Closed

Authenticated as class decorator bug #467

d0whc3r opened this issue Oct 13, 2018 · 4 comments

Comments

@d0whc3r
Copy link

d0whc3r commented Oct 13, 2018

Informations

Type  Version
Bug 4.32.0

Description

@Authenticated decorator in class decorator doesn't get options

Acceptance criterias

import { Authenticated, Controller, Get, RouteService } from '@tsed/common';

@Controller('/')
@Authenticated('somestring')
export class RestController {

  constructor(private routeService: RouteService) {
  }

  @Get('/')
  public getRoutes(): any {
    return this.routeService.getAll();
  }
}
@OverrideMiddleware(AuthenticatedMiddleware)
export class AuthMiddleware implements IMiddleware {
  private JWT_SECRET = Buffer.from(process.env.JWT_SECRET || '', 'base64');

  constructor() {
  }
  use(
    @EndpointInfo() endpoint: EndpointMetadata,
    @Request() request,
    @Response() response,
    @Next() next: Express.NextFunction) {

    // endpoint is undefined
  }
}

How could I get options if endpoint is undefined?
endpoint.store.get(AuthenticatedMiddleware) doesn't work

@d0whc3r d0whc3r changed the title Authenticated as class decorator Authenticated as class decorator bug Oct 15, 2018
@Romakita
Copy link
Collaborator

Hello,
Is not possible to use authenticated on class right know because authenticed decorator require option given to the decorator for the specific endpoint.
Isn’t a bug but an enhancement ;)

@d0whc3r
Copy link
Author

d0whc3r commented Oct 17, 2018

Well, @Authenticated decorator works well as class decorator, but it can't accept "options"

@Romakita
Copy link
Collaborator

Hum yes, because, @EndpointInfo() endpoint: EndpointMetadata is the method to retrieve option given to authenticated decorator.

The hack right now, should be something like that:

@Controller('/')
export class RestController {

  @Authenticated('somestring')
  @All('/')
  all() {} // catch all requests

  @Get('/')
  public getRoutes(): any {
    return this.routeService.getAll();
  }
}

@Romakita Romakita added this to the BACKLOG milestone Oct 27, 2018
@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 5.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants