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

Koa still return 404 when with Authorized #282

Closed
xujif opened this issue Sep 8, 2017 · 8 comments · Fixed by #283
Closed

Koa still return 404 when with Authorized #282

xujif opened this issue Sep 8, 2017 · 8 comments · Fixed by #283
Assignees
Labels
type: fix Issues describing a broken feature.

Comments

@xujif
Copy link

xujif commented Sep 8, 2017

version: 0.7.2
test code:

import { createExpressServer, createKoaServer,Action,JsonController, Get, Authorized } from "routing-controllers";
@JsonController()
export class TestClass {

    @Get('/no-auth')
    noAuth () {
        return {
            message: 'no auth'
        }
    }
    @Authorized()
    @Get('/auth')
    auth () {
        return {
            message: 'auth'
        }
    }
}
// when use createExpressServer can access /api/auth
const app = createKoaServer({
    routePrefix: "/api",
    currentUserChecker: (action: Action) => {
        return {
            user: 'user'
        }
    },
    authorizationChecker: (action: Action, roles: string[]) => {
        return true
    },
    controllers: [
        TestClass
    ]
})
console.log('listen at 8088')
app.listen(8088)

my package.json

{
  "name": "t",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "express": "^4.15.4",
    "koa": "^2.3.0",
    "koa-bodyparser": "^4.2.0",
    "koa-router": "^7.2.1",
    "routing-controllers": "^0.7.2",
    "typescript": "^2.5.2"
  }
}

@MichalLytek
Copy link
Contributor

Maybe just use this?

authorizationChecker: async(action: Action, roles: string[]) => {
    return true
},

@xujif
Copy link
Author

xujif commented Sep 8, 2017

@19majkel94 it worked. but still a bug.

@MichalLytek
Copy link
Contributor

@NoNameProvided
Looks like the error is here:
https://github.com/pleerock/routing-controllers/blob/master/src/driver/koa/KoaDriver.ts#L89

We just call next instead of return next(). And I found that @Diluka is the culprit:
177143a4#diff-112df671cfc9c4c162793234f846b6d0R105

@xujif
Copy link
Author

xujif commented Sep 8, 2017

@19majkel94 @NoNameProvided

    @Get('/user')
    user (@CurrentUser() user: any) {
        return user   // will return user  defined by currentUserChecker
    }
    @Get('/async-user')
    async asyncUser (@CurrentUser() user: any) {
        return user // raise 404 not found
    }

with a CurrentUser resolver ,still raise 404 when in a async action

@MichalLytek
Copy link
Contributor

with a CurrentUser resolver ,still raise 404 when in a async action

Nope, just checked:

import "reflect-metadata"
import {
    createExpressServer,
    createKoaServer,
    Action,
    JsonController,
    Get,
    Authorized,
    CurrentUser,
} from "routing-controllers";
@JsonController()
export class TestClass {

    @Get('/no-auth')
    noAuth () {
        return {
            message: 'no auth'
        }
    }
    @Authorized()
    @Get('/auth')
    auth () {
        return {
            message: 'auth'
        }
    }

    @Get('/user')
    user (@CurrentUser() user: any) {
        return {
            user, // will return user  defined by currentUserChecker
            path: '/user',
        }   
    }

    @Get('/async-user')
    async asyncUser (@CurrentUser() user: any) {
        return {
            user, // raise 404 not found
            path: '/async-user',
        }
    }
}
// when use createExpressServer can access /api/auth
const app = createKoaServer({
    routePrefix: "/api",
    currentUserChecker: (action: Action) => {
        return {
            user: 'user'
        }
    },
    authorizationChecker: (action: Action, roles: string[]) => {
        return true
    },
    controllers: [
        TestClass
    ]
})
console.log('listen at 8088')
app.listen(8088)

image

@MichalLytek MichalLytek self-assigned this Sep 8, 2017
@MichalLytek MichalLytek added the type: fix Issues describing a broken feature. label Sep 8, 2017
@xujif
Copy link
Author

xujif commented Sep 9, 2017

@19majkel94 it's still 404 when add an "@Authorized":

    @Get('/async-user')
    @Authorized()
    async asyncUser (@CurrentUser() user: any) {
        return {
            user, // raise 404 not found
            path: '/async-user',
        }
    }

@MichalLytek
Copy link
Contributor

it's still 404 when add an "@Authorized":

We will check that when the #283 PR has become merged.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: fix Issues describing a broken feature.
Development

Successfully merging a pull request may close this issue.

2 participants