feathersjs-ecosystem / authentication-client

[MOVED] The authentication client
https://github.com/feathersjs/feathers
MIT License
41 stars 19 forks source link

Why is "strategy" required for login? #94

Closed hongkongkiwi closed 6 years ago

hongkongkiwi commented 6 years ago

I'm wondering why is "strategy" required?

In my own app I have two strategies setup. I renamed them from 'local' to 'email' and 'username' respectively. Each has a different authentication field.

When authenticating with feathers using a REST API I can simply send the JSON, with either username or email field without specifically defining the strategy. So I'm wondering why this plugin forces me to explicitly specify the strategy?

daffl commented 6 years ago

It is required for Websockets authentication and when the parameters are ambiguous and will be mandatory everywhere in the next version of Feathers authentication.

hongkongkiwi commented 6 years ago

Got it. This would be be good to document. Is there a way for us to capture the error that is sent to the client and send something else? I'm keen for the "strategy" to be a bit obscured. For example I would like to use "type" as the field that is sent to the server instead of strategy.

daffl commented 6 years ago

You can customize the authentication workflow the same as any other service using hooks:

app.service('authentication').hooks({
  before: {
    create(context) {
      context.data.strategy = context.data.type;
    }
  },
  error: {
    create(context) {
      // customize context.error here
    }
  }
});