mean-expert-official / loopback-component-realtime

The LoopBack Component that turns this great framework into a powerful real-time platform
MIT License
30 stars 17 forks source link

Custom AccessToken model error #43

Closed WhatzzUp closed 7 years ago

WhatzzUp commented 7 years ago

Hello guys,

we created a custom AccesToken model "extendendAccessToken" and remove the old "AccesToken" from the "model-config.json"

Our "model-config.json"

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins",
      "../node_modules/@mean-expert/loopback-stats-mixin/dist",
      "../node_modules/@mean-expert/loopback-component-realtime/dist/mixins",
      "../node_modules/loopback-ds-timestamp-mixin"
    ]
  },
  "ACL": {
    "dataSource": "mysql",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "mysql",
    "public": false
  },
  "Role": {
    "dataSource": "mysql",
    "public": false
  },
  "UserActivity": {
    "dataSource": "mysql",
    "public": true
  },
  "attachment": {
    "dataSource": "mysql",
    "public": true,
    "options": {
      "remoting": {
        "sharedMethods": {
          "*": true,
          "upload": true
        }
      }
    }
  },
  "userWidget": {
    "dataSource": "mysql",
    "public": true
  },
  "userDashboard": {
    "dataSource": "mysql",
    "public": true
  },
  "widget": {
    "dataSource": "mysql",
    "public": true
  },
  "extendedUser": {
    "dataSource": "mysql",
    "public": true,
    "acls": [
      {
        "principalType": "ROLE",
        "principalId": "$everyone",
        "permission": "ALLOW",
        "property": "userLogin"
      }
    ]
  },
  "extendedAccessToken": {
    "dataSource": "mysql",
    "public": false
  }
}

After a user successfully logged in, the server throw the following error message:

C:\unicorn\server\node_modules\@mean-expert\loopback-component-realtime\dist\drivers\io.driver.js:123
                    var token = AccessToken.findOne({

If we add the standard "AccessToken" model back to the "model-config.json" everything works correct. What is necessary to use our custome AccesToken model instead of the standard AccessToken?

Cheers

Chris

WhatzzUp commented 7 years ago

I found the problem:

In the file "io.driver.js"

node_modules\@mean-expert\loopback-component-realtime\dist\drivers\io.driver.js

changed line 122 from

var AccessToken = _this.options.app.models.AccessToken;

to

var AccessToken = _this.options.app.models.extendedAccessToken;

and now it works.

Any idear, how to set a custom AccessToken without changing this line?

jonathan-casarrubias commented 7 years ago

@WhatzzUp thanks for verifying... Currently there is no custom access token implementation, but I think is easy to implement....

Actually... If you help me test if my idea works would be awesome....

You need to change that line of code for the following:

          var AccessToken = _this.options.custom && _this.options.custom.AccessToken
                          ? _this.options.app.models[_this.options.custom.AccessToken]
                          : _this.options.app.models.AccessToken;

And then in the server/component-config.json

  "@mean-expert/loopback-component-realtime": {
    "debug": false,
    "auth": true,
    "custom": {
      "AccessToken": "extendedAccessToken"
    }
   .....
  }

Let me know if that works, I'm assuming it will... If does I can publish a patch including that code.

Cheers Jon

WhatzzUp commented 7 years ago

@jonathan-casarrubias thank you so much for your quick responses!

It works like a charm! :tada:

And once again many thanks @jonathan-casarrubias!

WhatzzUp commented 7 years ago

@jonathan-casarrubias will this "feature" released in the future? :)