Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

REST auth/local not working if socketio() not set #72

@fastlorenzo

Description

@fastlorenzo

I encountered the following issue while trying to work with multiple feathers instances :

The following configuration throws an error if I try to POST to /auth/local with username and password :

var app = feathers()
    .configure(rest())
    .configure(hooks())
    // .configure(socketio())
    .use(bodyParser.json())
    .use(bodyParser.urlencoded({ extended: true }))
    .configure(authentication({
      setUpSuccessRedirect: false,
      setUpFailureRedirect: false,
      idField: 'id',
      userEndpoint: serviceEndpoint + SERVICE_ENDPOINT_USER,
      token: {
        secret: JWT_SECRET,
        tokenEndpoint: serviceEndpoint + SERVICE_ENDPOINT_AUTH_TOKEN,
        userEndpoint: serviceEndpoint + SERVICE_ENDPOINT_USER,
        jwtOptions: {
          expiresIn: JWT_EXPIRES_IN
        },
      },
      local: {
        type: 'local',
        usernameField: 'username',
        userEndpoint: serviceEndpoint + SERVICE_ENDPOINT_USER,
        localEndpoint: serviceEndpoint + SERVICE_ENDPOINT_AUTH_LOCAL,
        successRedirect: serviceEndpoint + SERVICE_ENDPOINT_AUTH_SUCCESS,
        tokenEndpoint: serviceEndpoint + SERVICE_ENDPOINT_AUTH_TOKEN,
        jwtOptions: {
          expiresIn: JWT_EXPIRES_IN
        },
      },
      localEndpoint: serviceEndpoint + SERVICE_ENDPOINT_AUTH_LOCAL,
      tokenEndpoint: serviceEndpoint + SERVICE_ENDPOINT_AUTH_TOKEN
    }));

var feathersapp = feathers().use('/api/v1/rest', app);

Error :

TypeError: Cannot read property 'service' of undefined
<br> &nbsp; &nbsp;at Object.checkCredentials (/root/RAF/api/node_modules/feathers-authentication/lib/services/local/index.js:80:15)
<br> &nbsp; &nbsp;at Strategy.authenticate (/root/RAF/api/node_modules/passport-local/lib/strategy.js:90:12)
<br> &nbsp; &nbsp;at attempt (/root/RAF/api/node_modules/passport/lib/middleware/authenticate.js:348:16)
<br> &nbsp; &nbsp;at authenticate (/root/RAF/api/node_modules/passport/lib/middleware/authenticate.js:349:7)
<br> &nbsp; &nbsp;at /root/RAF/api/node_modules/feathers-authentication/lib/services/local/index.js:137:9
<br> &nbsp; &nbsp;at new Promise (/root/RAF/api/node_modules/core-js/modules/es6.promise.js:197:7)
<br> &nbsp; &nbsp;at Object.create (/root/RAF/api/node_modules/feathers-authentication/lib/services/local/index.js:116:14)
<br> &nbsp; &nbsp;at Object.wrapper (/root/RAF/api/node_modules/feathers/lib/mixins/promise.js:30:28)
<br> &nbsp; &nbsp;at Object.&lt;anonymous&gt; (/root/RAF/api/node_modules/uberproto/lib/proto.js:30:17)
<br> &nbsp; &nbsp;at Object.wrapped (/root/RAF/api/node_modules/rubberduck/lib/rubberduck.js:63:19)
<br> &nbsp; &nbsp;at /root/RAF/api/node_modules/feathers-hooks/lib/before.js:53:20
<br> &nbsp; &nbsp;at new Promise (/root/RAF/api/node_modules/core-js/modules/es6.promise.js:197:7)
<br> &nbsp; &nbsp;at /root/RAF/api/node_modules/feathers-hooks/lib/before.js:40:18
<br> &nbsp; &nbsp;at run (/root/RAF/api/node_modules/core-js/modules/es6.promise.js:104:47)
<br> &nbsp; &nbsp;at /root/RAF/api/node_modules/core-js/modules/es6.promise.js:115:28
<br> &nbsp; &nbsp;at flush (/root/RAF/api/node_modules/core-js/modules/$.microtask.js:19:5)

If I uncomment the following line to use socketio it works :
// .configure(socketio())

I think the app variable is not available in services/local/index.js if you don't setup socketio in feathers.

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