-
Notifications
You must be signed in to change notification settings - Fork 401
Bug with Authorized() (only 0.7.1) #240
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Could you describe the problem with more details and code snippets? I don't know what happens, what is the shape of request, etc. etc. BTW I see that you use async/await with bluebird, I don't know if it's a good idea 😕 |
i tried to reproduce from zero and POST http://localhost:3001/questions/ app.js import "reflect-metadata";
import { Action } from 'routing-controllers'
import { QuestionController } from "./QuestionController";
import { createKoaServer } from 'routing-controllers'
createKoaServer({
controllers: [QuestionController],
authorizationChecker: async (action: Action, roles?: string[]) => {
return true;
}
}).listen(3001);
console.log("Express server is running on port 3001. Open http://localhost:3001/questions/"); QuestionController.ts import { Service } from 'typedi'
import { Authorized, JsonController, Post, Body } from 'routing-controllers';
@Service()
@JsonController()
export class QuestionController {
@Authorized()
@Post("/questions")
all() {
return { "test": "ok" }
}
} or with class validator import { Service } from 'typedi'
import { Authorized, JsonController, Post, Body } from 'routing-controllers';
import { IsString } from 'class-validator'
export class LoginParams {
@IsString()
username: string
@IsString()
password: string
}
@Service()
@JsonController()
export class QuestionController {
@Authorized()
@Post("/questions")
all( @Body() params: LoginParams) {
return { "test": "ok" }
}
}
|
Earlier you said that:
So it also happens with sync ones like |
Apparently yes. In my project slightly different behavior. But in both cases i got 404 and downgrade to alpha.15 solve this problem. |
@maxsh8x thanks for the report, I confirm the issue. It was introduced after A minimal reproducible use case: import 'reflect-metadata';
import { createKoaServer, JsonController, Authorized, Post, Action } from 'routing-controllers';
@JsonController()
export class SomeController {
@Authorized()
@Post("/questions")
public save() {
return {};
}
}
createKoaServer({
authorizationChecker: async (action: Action, roles: string[]) => {
const token = action.request.headers["authorization"];
return token ? true : false;
}
}).listen(3000) The above snippet have the following behaviour:
PS: You can write the type of the code after the backticks to have highlighting like: |
The problem is most likely here KoaDriver.ts#L106 it was introduced in 177143a we should return the promise as before. |
Created a PR for this at #242. |
Ok, so I'm closing this issue. @maxsh8x feel free to reopen if the issue will still exist in 0.7.2. |
@NoNameProvided @19majkel94 not fixed yet. Still 404 for decorated routes after 0.7.0-alpha.15 |
It was fixed in 0.7.2. |
@NoNameProvided app.ts import 'reflect-metadata';
import { Container } from 'typedi';
import { createKoaServer, useContainer, Action } from 'routing-controllers';
import { SomeController } from './controller'
useContainer(Container);
createKoaServer({
controllers: [SomeController],
authorizationChecker: async (action: Action, roles: string[]) => {
const token = action.request.headers["authorization"];
return token ? true : false;
}
}).listen(3000) controller.ts import { Service } from 'typedi'
import { JsonController, Authorized, Get } from 'routing-controllers';
import { SomeRepository } from './repository'
@Service()
@JsonController()
export class SomeController {
constructor(
private someRepository: SomeRepository
) { }
@Authorized()
@Get("/questions")
async save() {
const data = await this.someRepository.save()
return data
}
} repository.ts import { Service } from 'typedi';
@Service()
export class SomeRepository {
save() {
return Promise.resolve({})
}
} |
Works ok on 0.7.2: import "reflect-metadata";
import { Service, Container } from "typedi";
import { JsonController, Authorized, Get, createKoaServer, useContainer, Action } from "routing-controllers";
@Service()
export class SomeRepository {
save() {
return Promise.resolve({});
}
}
@Service()
@JsonController()
export class SomeController {
constructor(private someRepository: SomeRepository) {}
@Authorized()
@Get("/questions")
async save() {
const data = await this.someRepository.save();
return data;
}
}
useContainer(Container);
createKoaServer({
controllers: [SomeController],
authorizationChecker: async (action: Action, roles: string[]) => {
return true;
},
}).listen(3000, () => console.log("listening on 3000")); |
@19majkel94
|
I don't know, try this?
|
unfortunately same result. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Uh oh!
There was an error while loading. Please reload this page.
0.7.0-alpha.15 works fine
The text was updated successfully, but these errors were encountered: