Page Contents

Home > @loopback/authentication > AuthenticationBindings > AUTH_ACTION

AuthenticationBindings.AUTH_ACTION variable

Key used to inject the authentication function into the sequence.

Signature:

AUTH_ACTION: BindingKey<AuthenticateFn>

Example

class MySequence implements SequenceHandler {
  constructor(
    @inject(AuthenticationBindings.AUTH_ACTION)
    protected authenticateRequest: AuthenticateFn,
    // ... other sequence action injections
  ) {}

  async handle(context: RequestContext) {
    try {
      const {request, response} = context;
      const route = this.findRoute(request);

     // Authenticate
      await this.authenticateRequest(request);

      // Authentication successful, proceed to invoke controller
      const args = await this.parseParams(request, route);
      const result = await this.invoke(route, args);
      this.send(response, result);
    } catch (err) {
      this.reject(context, err);
    }
  }
}