{"action":"opened","issue":{"url":"https://api.github.com/repos/nestjs/nest/issues/787","repository_url":"https://api.github.com/repos/nestjs/nest","labels_url":"https://api.github.com/repos/nestjs/nest/issues/787/labels{/name}","comments_url":"https://api.github.com/repos/nestjs/nest/issues/787/comments","events_url":"https://api.github.com/repos/nestjs/nest/issues/787/events","html_url":"https://github.com/nestjs/nest/issues/787","id":333085790,"node_id":"MDU6SXNzdWUzMzMwODU3OTA=","number":787,"title":"How do I change the order of providers?","user":{"login":"bhenav","id":14276250,"node_id":"MDQ6VXNlcjE0Mjc2MjUw","avatar_url":"https://avatars0.githubusercontent.com/u/14276250?v=4","gravatar_id":"","url":"https://api.github.com/users/bhenav","html_url":"https://github.com/bhenav","followers_url":"https://api.github.com/users/bhenav/followers","following_url":"https://api.github.com/users/bhenav/following{/other_user}","gists_url":"https://api.github.com/users/bhenav/gists{/gist_id}","starred_url":"https://api.github.com/users/bhenav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhenav/subscriptions","organizations_url":"https://api.github.com/users/bhenav/orgs","repos_url":"https://api.github.com/users/bhenav/repos","events_url":"https://api.github.com/users/bhenav/events{/privacy}","received_events_url":"https://api.github.com/users/bhenav/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-17T19:15:49Z","updated_at":"2018-06-17T19:15:49Z","closed_at":null,"author_association":"NONE","body":"## I'm submitting a...\r\n<pre><code>\r\n[ ] Regression <!--(a behavior that used to work and stopped working in a new release)-->\r\n[ ] Bug report\r\n[ ] Feature request\r\n[X] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.\r\n</code></pre>\r\n\r\n## Current behavior\r\n<pre><code>\r\nimport { ExtractJwt, Strategy } from 'passport-jwt';\r\nimport { PassportStrategy } from '@nestjs/passport';\r\nimport { Injectable, UnauthorizedException } from '@nestjs/common';\r\nimport { JwtPayload } from '../models/jwt-payload.interface';\r\nimport { UserService } from '../../user/services/user.service';\r\n\r\n@Injectable()\r\nexport class JwtStrategy extends PassportStrategy(Strategy) {\r\n  constructor(private readonly userService: UserService) {\r\n    super({\r\n      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),\r\n      secretOrKey: 'ibh-ali-ata-bak',\r\n    });\r\n  }\r\n\r\n  async validate(payload: JwtPayload, done) {\r\n    const user = await this.userService.findOneByJwtPayload(payload);\r\n    if (!user) {\r\n      return done(new UnauthorizedException(), false);\r\n    }\r\n    done(null, user);\r\n  }\r\n}\r\n</code></pre>\r\n\r\n<pre><code>\r\nimport { Module } from '@nestjs/common';\r\nimport { AppController } from './app.controller';\r\nimport { AppService } from './app.service';\r\nimport { DatabaseModule } from '../database/database.module';\r\nimport { RootModule } from '../../modules/root.module';\r\nimport { APP_GUARD } from '@nestjs/core';\r\nimport { RoleGuard } from '../../modules/role/guards/role.guard';\r\nimport { JwtStrategy } from '../../modules/auth/providers/jwt.strategy';\r\n\r\n@Module({\r\n  imports: [DatabaseModule, RootModule],\r\n  controllers: [AppController],\r\n  providers: [\r\n    JwtStrategy,\r\n    AppService,\r\n    {\r\n      provide: APP_GUARD,\r\n      useClass: RoleGuard,\r\n    },\r\n  ],\r\n})\r\nexport class AppModule {}\r\n</code></pre>\r\n\r\n<pre><code>\r\nimport { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';\r\nimport { Reflector } from '@nestjs/core';\r\n\r\n@Injectable()\r\nexport class RoleGuard implements CanActivate {\r\n  constructor(private readonly reflector: Reflector,) {}\r\n\r\n  canActivate(context: ExecutionContext): boolean {\r\n    const handlerAuthorities = this.reflector.get<string[]>('authorities', context.getHandler()) || [];\r\n    const classAuthorities = this.reflector.get<string[]>('authorities', context.getClass()) || [];\r\n    const authorities = [...handlerAuthorities, ...classAuthorities];\r\n\r\n    const request = context.switchToHttp().getRequest();\r\n    const user = request.user;\r\n    console.log('role guard --> ', user);\r\n    setTimeout(() => {\r\n      console.log('role guard setTimeout --> ', request.user);\r\n    }, 20);\r\n    if (!authorities || !authorities.length || !user) {\r\n      return true;\r\n    }\r\n    const userAuthoritiesInRoles = user ? (user.roles || []).reduce((all, role) => all.concat(role.authorities), []) : [];\r\n    const userAuthorities = user ? (user.authorities || []).concat(userAuthoritiesInRoles) : [];\r\n    const hasRole = () => userAuthorities.some(role => !!authorities.find(item => item === role));\r\n    return user && userAuthorities && hasRole();\r\n  }\r\n}\r\n\r\n\r\n[Nest] 5819   - 2018-6-17 12:11:17   [NestApplication] Nest application successfully started +0ms\r\nrole guard -->  undefined\r\nrole guard setTimeout -->  { _id: 5b2691ed13d0b911a720155c,\r\n  username: 'bhenav',\r\n  password: '11111111',\r\n  firstName: 'kutbettin',\r\n  lastName: 'yavuz',\r\n  email: 'admin@kutbettin.com',\r\n  customers: [],\r\n  __v: 0 }\r\n</code></pre>\r\n\r\n\r\n\r\n## Environment\r\n\r\n<pre><code>\r\nNest version: 5.2.0\r\n\r\nFor Tooling issues:\r\n- Node version: 8.11.2\r\n- Platform:  Mac\r\n\r\nOthers:\r\nyarn version: 1.7.0\r\nnpm version: 5.6.0\r\n</code></pre>\r\n"}}
{"actor":{"display_login":"bhenav"}}