Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Feathers 4.0.0-pre] Trying every strategy and throwing is wasteful #1323

Copy link
Copy link
@KidkArolis

Description

@KidkArolis
Issue body actions

I have custom errors in my LocalStrategy subclass, e.g.:

async comparePassword(entity, password) {
    if (entity.googleId) {
      throw new errors.GSuiteEmail(`Please use 'Sign in with Google' button`)
    }
    return super.comparePassword(entity, password)
}

Because of this, I can't order my strategies as [jwt, local], I have to order them [local, jwt]. But jwt is obviously much more frequently used, and so it seems wasteful that the local has to always be tried first and throw an error right on this line:

if (data.strategy && data.strategy !== this.name) {
      throw new NotAuthenticated(errorMessage);
    }

This has another strange effect, this swallows the error from jwt, even though that's the more appropriate error. (in fact, this point is the same point made above, but reversed).

Proposal: in authentication/core, do not even run those strategies whose name doesn't match data.strategy. Then, check if any strategies were in fact run and only then proceed.

This way:

  • only relevant strategies will be executed
  • the most appropriate error will be shown
  • the ordering of [local, jwt] or [jwt, local] becomes less important
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.