Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: this.hooks is not a function #621

Closed
hhchow7 opened this issue Apr 8, 2021 · 0 comments
Closed

TypeError: this.hooks is not a function #621

hhchow7 opened this issue Apr 8, 2021 · 0 comments

Comments

@hhchow7
Copy link

hhchow7 commented Apr 8, 2021

I am using Feathers.js for the backend.

This is the original response from POST /authentication

{
    "accessToken": "XXXXX",
    "authentication": {
        "strategy": "local",
        "accessToken": "XXXXX",
        "payload": {
            "iat": 1616402936,
            "exp": 1616489336,
            "aud": "https://yourdomain.com",
            "iss": "feathers",
            "sub": "c15ef318-68fc-471c-9710-52f14d87abda",
            "jti": "57d103e1-c81b-4fc6-8bbe-952b74aaf8e3"
        }
    },
    "user": {
        "id": "c15ef320-68fc-471c-9710-52f14d87ccda",
        "email": "[email protected]",
    }
}

I want to discard the authentication field from the response, so I modified authentication.js as:

const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');
const { discard, iff, isProvider, lowerCase } = require('feathers-hooks-common')

module.exports = app => {
  const authentication = new AuthenticationService(app);

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());

  app.use('/authentication', authentication);
  app.service('/authentication').hooks({
    before: {
      create: [lowerCase('email')],
      update: [lowerCase('email')],
      patch: [lowerCase('email')],
    },
    after: {
      create: [discard('authentication')]
    }
  });
  app.configure(expressOauth());
};

Then an error occurs:

/server/node_modules/@feathersjs/authentication/lib/service.js:141

this.hooks({

^


TypeError: this.hooks is not a function

at Object.setup (/server/node_modules/@feathersjs/authentication/lib/service.js:141:14)

at /server/node_modules/@feathersjs/feathers/lib/application.js:139:17

at Array.forEach (<anonymous>)

at Function.setup [as _super] (/server/node_modules/@feathersjs/feathers/lib/application.js:133:32)

at Function.setup (/server/node_modules/@feathersjs/socketio/lib/index.js:70:30)

at Function.newMethod (/server/node_modules/uberproto/lib/proto.js:34:20)

at Function.app.setup (/server/src/sequelize.js:20:29)

at Function.listen (/server/node_modules/@feathersjs/express/lib/index.js:63:12)

at Function.newMethod (/server/node_modules/uberproto/lib/proto.js:34:20)

at Function.listen (/server/node_modules/@feathersjs/socketio/lib/index.js:39:25)

[nodemon] app crashed - waiting for file changes before starting...

What is wrong here?

@hhchow7 hhchow7 closed this as completed Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant