I am trying to set up a sample strong loop application and I'm getting the following error when I try to tryout the post api using /explorer.
"Cannot call AccessToken.findById(). The findById method has not been setup.. The PersistedModel has not been correctly attached to a DataSource."
I ran through and installed slc loopback:acl with the following settings:
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}
],
However, these settings do not seem to apply to my model.
I had the same problem: what solved this for me was to delete my browser's Local Storage (in "Resources" tab in developper tools). The explanation to this was I'd been using another loopback app which uses token-based auth.
I have the same error message and the solution is not available as everyone has there own thought.
So What works for me If you extended AccessToken according to reference given in loopback-component-passport,
Just don't remove base AccessToken from model-config keep both. Don't worry as loopback only going to use extended model to keep Token.
model-config.json
`'....
,
"AccessToken": {
"dataSource": "adnexux",
"public": false
},
"accessToken": {
"dataSource": "adnexux",
"public": false
},
...'`
Then Just add this to middleware.json
`....
,
"loopback#token": {
"params": {
"model": "accessToken"
}
}
},
...`
If Error Is without Extending the accessToken:
Then Just check model config if model is connected to data source.
`....
"AccessToken": {
"dataSource": "adnexux",
"public": false
},
.....`
And To get current User you can paste this code in server.js
`'app.use(function setCurrentUser(req, res, next) {
if (!req.accessToken) {
return next();
}
app.models.user.findById(req.accessToken.userId, function(err, user) {
if (err) {
return next(err);
}
if (!user) {
return next(new Error('No user with this access token was found.'));
}
res.locals.currentUser = user;
next();
});
});'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With