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

local authentication bug with users as sequelize service #47

Closed
jarnojellesma opened this issue Dec 28, 2017 · 3 comments
Closed

local authentication bug with users as sequelize service #47

jarnojellesma opened this issue Dec 28, 2017 · 3 comments

Comments

@jarnojellesma
Copy link

Expected behavior

Authenticate user

Actual behavior

className: "general-error"
code: 500
data: Object {  }
errors: Object {  }
message: "the `id` property must be set on the entity service for authentication"
name: "GeneralError"
stack: "FeathersError@http://localhost:3000/_nuxt/app.e42a4ab34fc5e966dc8b.js:8069:19\nGeneralError@http://localhost:3000/_nuxt/app.e42a4ab34fc5e966dc8b.js:8176:3\nconvert@http://localhost:3000/_nuxt/app.e42a4ab34fc5e966dc8b.js:8245:7\ntoError@http://localhost:3000/_nuxt/app.e42a4ab34fc5e966dc8b.js:8392:9\n"
type: "FeathersError"

How I solved it

@feathersjs/authentication-local in lib/verifier.js:

Add this.service.id = this.service.sequelize.id in the constructor.

class LocalVerifier {
  constructor (app, options = {}) {
    this.app = app;
    this.options = options;
    this.service = typeof options.service === 'string' ? app.service(options.service) : options.service;
    this.service.id = this.service.sequelize.id; // <--- this line

    if (!this.service) {
      throw new Error(`options.service does not exist.\n\tMake sure you are passing a valid service path or service instance and it is initialized before @feathersjs/authentication-local.`);
    }

    this._comparePassword = this._comparePassword.bind(this);
    this._normalizeResult = this._normalizeResult.bind(this);
    this.verify = this.verify.bind(this);
  }

System configuration

"@feathersjs/authentication": "^2.1.0",
"@feathersjs/authentication-jwt": "^1.0.1",
"@feathersjs/authentication-local": "^1.0.2",
"@feathersjs/authentication-oauth2": "^1.0.2",
"@feathersjs/configuration": "^1.0.1",
"@feathersjs/errors": "^3.2.0",
"@feathersjs/express": "^1.1.2",
"@feathersjs/feathers": "^3.0.2",

@daffl
Copy link
Member

daffl commented Dec 29, 2017

The id property for a feathers-sequelize service is being set here so it should be available. Is this a normal setup with that adapter?

@jarnojellesma
Copy link
Author

Ah I see, I am using a custom class on top of the feathers-sequelize class and I didn't add that line of code there. Thanks!

@daffl
Copy link
Member

daffl commented Dec 29, 2017

If you have a custom constructor, this should also be solvable by calling super(options) in it.

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

2 participants