Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Support dot notation #7

Closed
elfey opened this issue Jan 25, 2017 · 9 comments
Closed

Support dot notation #7

elfey opened this issue Jan 25, 2017 · 9 comments

Comments

@elfey
Copy link
Contributor

elfey commented Jan 25, 2017

This is just a simple feature request, but it'd be great if usernameField and passwordField both supported dot notation.

@lionelrudaz
Copy link

I confirm, this would be awesome. I talked about that in the #help channel on Slack. If you don't use a flat structure in your user service response (for example with JSON API standard), you simply can't do anything. I'm currently commenting the line 52 of verifier.js with my own path, but that's not good.

Let me know if we can help.

Cheers,

Lionel

@daffl
Copy link
Member

daffl commented Jan 26, 2017

The workaround right now is to implement your own verifier methods.

It's a good feature though and definitely worth adding. We'll happily accept a pull request with tests that changes https://github.com/feathersjs/feathers-authentication-local/blob/master/src/verifier.js#L23 to use lodash .get:

const hash = get(entity, this.options.passwordField);

@daffl
Copy link
Member

daffl commented Jan 27, 2017

You can probably copy the test from https://github.com/feathersjs/feathers-authentication-local/blob/master/test/verifier.test.js#L92-L98 to the next line and change it to this

describe('password comparison succeeds', () => {
  it('allows dot notation for password field', () => {
    const oldPasswordField = verifier.options.passwordField;

    verifier.options.passwordField = 'nested.password';

    return verifier._comparePassword({
      nested: user
    }, 'admin').then(result => {
      expect(result).to.deep.equal(user);
      verifier.options.passwordField = oldPaswordField;
    });
  });
});

@elfey
Copy link
Contributor Author

elfey commented Jan 27, 2017

Just solved this via #8, will close once reviewed and merged

@daffl I'm new to this whole Git thing, let me know if you have any tips or suggestions about Git or testing in general. I'm elf from the Slack channels.

@lionelrudaz
Copy link

Thanks @daffl and @theonlyelf, looking forward to use it!

@elfey
Copy link
Contributor Author

elfey commented Jan 27, 2017

We've decided to remove the usernameField dot notation implementation. It wasn't exactly functional, and with so many different database drivers, wouldn't have worked across too many.

For now, it's a better idea to write your own custom verifier function that queries documents with dot notation.

@elfey elfey closed this as completed Jan 27, 2017
@lionelrudaz
Copy link

Awesome, thanks. I finally ended up doing my own Verifier for exactly this reason.

@elfey
Copy link
Contributor Author

elfey commented Feb 3, 2017

@lionelrudaz do you have an example? I haven't gotten the chance to hop in an write my own yet.

@lionelrudaz
Copy link

Sure, here it is: https://github.com/lionelrudaz/api.wellnow.ch/blob/master/src/verifier.js

I call it from the app: https://github.com/lionelrudaz/api.wellnow.ch/blob/master/src/app.js

Hope this helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants