Skip to content

How to report HttpErrors.Forbidden from authenticate action #2212

@fiftikhar

Description

@fiftikhar

Suggestion
I have implement JWTStrategy
every thing working fine. now I am trying to further authenticate according to user roles
e.g if logged in user is not ADMIN raised HttpErrors.Forbidden error

current strategy-adapter.js code only raise InternalServerError if I pass error in cb() of JWTStrategy

I have changed strategy-adapter.js
reject(new rest_1.HttpErrors.InternalServerError(error)); to
reject(error); and pass
cb(new HttpErrors.Forbidden(), false); in auth-strategy.provides.ts
which working according to my requirement
my question is there best way to implement changes in my code instead of changing in @loopback/authentication module directly

Existing CODE
@loopback/authentication/strategy-adapter.js

strategy.error = function (error) {              
                reject(new rest_1.HttpErrors.InternalServerError(error));
            };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions