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

500 ResolutionError: The key 'security.user' is not bound to any value #7079

Closed
naveeng2228 opened this issue Feb 1, 2021 · 4 comments
Closed

Comments

@naveeng2228
Copy link

Hello Everyone,

I'm having the following issue since couple of weeks. I've tried all possible ways but no luck.

Code:

import {authenticate} from '@loopback/authentication';
import {repository} from '@loopback/repository';
import {get} from '@loopback/rest';
import {TblSellerProductMasterRepository} from '../repositories';

@authenticate.skip()
export class StoreFrontController {
  constructor(
    @repository(TblSellerProductMasterRepository)
    public productsMasterRepo: TblSellerProductMasterRepository
  ){}

  @get("/sf/products")
  async getSFProducts(): Promise<object> {
    return {};
  }
}

Error Log:

Unhandled error in GET /sf/products: 500 ResolutionError: The key 'security.user' is not bound to any value in context InterceptedInvocationContext-cR-VBcMLTZient5J4gh2pg-19 (context: InterceptedInvocationContext-cR-VBcMLTZient5J4gh2pg-19, binding: security.user, resolutionPath: @StoreFrontController.prototype.products[0])
    at InterceptedInvocationContext.getValueOrPromise (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\context.ts:810:13)
    at PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolver.ts:159:20
    at PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolution-session.ts:157:13
    at tryCatchFinally (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\value-promise.ts:222:14)     
    at Object.tryWithFinally (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\value-promise.ts:197:10)
    at Function.runWithInjection (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolution-session.ts:156:12)
    at resolve (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolver.ts:143:38)
    at PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolver.ts:246:12
    at Object.resolveList (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\value-promise.ts:169:28)  
    at Object.resolveInjectedArguments (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\resolver.ts:224:10)
    at invokeTargetMethodWithInjection (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\invocation.ts:223:25)
    at InterceptedInvocationContext.invokeTargetMethod (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\invocation.ts:119:14)
    at targetMethodInvoker (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\interceptor.ts:349:23)   
    at PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\interceptor-chain.ts:218:14
    at Object.transformValueOrPromise (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\value-promise.ts:298:12)
    at GenericInterceptorChain.invokeNextInterceptor (PROJECT_URL\lb4_web_services\node_modules\@loopback\context\src\interceptor-chain.ts:213:12)

Your help is highly appreciated.
Thanks in advance.

@marioestradarosa
Copy link
Contributor

marioestradarosa commented Apr 8, 2021

@naveeng2228 ,

Because you are using @authenticate() decorator, the @loopback/authentication component is asking that you inject the userObject in your constructor like so:

@authenticate.skip()
export class StoreFrontController {
  constructor(
    @inject(SecurityBindings.USER, {optional: true})
    public user: UserProfile,
    @repository(TblSellerProductMasterRepository)
    public productsMasterRepo: TblSellerProductMasterRepository
  ){}

 

Of course that means, that you need to also import the following.

import {SecurityBindings, UserProfile} from '@loopback/security';

On a side note, be aware that you don't need to specify @authenticate.skip() at the controller level. If you intend to not use any @authenticate for all methods for this controller in particular, just don't place this decorator (provided that you don't have have the option to enable authentication for all your controllers).

@achrinza
Copy link
Member

Closing due to inactivity.

@sudheersuri
Copy link

sudheersuri commented Aug 26, 2023

I haved injected user object in constructor yet am receiving this issue


constructor(
    @inject(TokenServiceBindings.TOKEN_SERVICE)
    public jwtService: TokenService,
    @inject(UserServiceBindings.USER_SERVICE)
    public userService: AuthUserService,
    @inject(SecurityBindings.USER, {optional: true})
    public user: UserProfile,
    @repository(UserRepository) 
    protected userRepository: UserRepository,
  ) {}

Request GET /whoAmI failed with status code 500. ResolutionError: The key 'security.user' is not bound to any value in context InterceptedInvocationContext-vac6cmCsQM-1ar5t08Mnvw-12 (context: InterceptedInvocationContext-vac6cmCsQM-1ar5t08Mnvw-12, binding: security.user, resolutionPath: @UserController.prototype.whoAmI[0])

@moizaltaf53
Copy link

I am also getting the same error fellas!
is there any end to the world of errors

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

5 participants