Closed jmls closed 9 years ago
found the problem
my model-config.json was missing the line
"./node_modules/loopback-component-passport/lib/models"
Hello,
I tried your solution but still not working by adding it to sources, any other suggestion?
"_meta": {
"sources": [
"./node_modules/loopback-component-passport/lib/models",
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
]
},
Thanks,
same problem
I solved it by adding in model-config.json because I frogot them
"accessToken": {
"dataSource": "db",
"public": true
},
"userCredential": {
"dataSource": "db",
"public": true
},
"userIdentity": {
"dataSource": "db",
"public": true
}
Thanks, works!
note: Use UserCredential
and UserIdentity
instead of userCredential
and userIdentity
else, model not found.
Same error here and none of the solutions work for me. The models are undefined at the moment of time theyre accessed.
Turns out that I need to boot the app before the models can be accessed.
@johannesjo solution works. place the code after the boot.
yes thanks @johannesjo
Looks like you guys managed to solve this one. Can I close this @jmls?
Closing due to inactivity. I will reopen it if you guys are still running into issues.
Thanks, works!
note: Use UserCredential and UserIdentity instead of userCredential and userIdentity
else, model not found.
=> Is that fine to use the same name UserCredential and UserIdentity with first capital ?
I'm still having issues with this...I've tried all of the mentioned solutions except for @johannesjo solution. I'm not sure that I understand what he means by "The models are undefined at the moment of time theyre accessed." and "Turns out that I need to boot the app before the models can be accessed." Is this referring to booting your strongloop application (i.e. slc start appName)? I am new to strongloop and passport. I've been referencing this https://github.com/strongloop/loopback-example-passport to get started.
I'm sure it's just user error, but any help would be appreciated.
Thanks
Edit: Just realized what was meant by the "boot". For clarification, it's the literal boot function at the bottom of server.js file. You need to make sure the boot is before running passportConfigurator.setupModels(). Looks like this should resolve the issue if none of the above solutions worked for you.
please be aware of your folder structure
because the model-config is in the server
folder then the sources path should be
"../node_modules/loopback-component-passport/lib/models"
which is one directory back
i i have to change the server.js file created with the generator, changing
`boot(app, __dirname, function(err) { if (err) throw err;
// start the server if $ node server.js
if (require.main === module)
app.start();
});`
to boot(app, __dirname);
inserting the passportConfigurator setModels inside the callback functions was not working (i really don't know why).
structure of you server.js file should be like this as mentioned by @johannesjo
// start the web server
return app.listen(() => {
if (app.get('loopback-component-explorer')) {
}
});
};
boot(app, __dirname, (err) => {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module) {
app.start();
}
});
// Set up related models
passportConfigurator.setupModels({
userModel: app.models.account,
userIdentityModel: app.models.userIdentity,
userCredentialModel: app.models.userCredential
});
// Configure passport strategies for third party auth providers
for(var s in config) {
var c = config[s];
c.session = c.session !== false;
passportConfigurator.configureProvider(s, c);
}```
I'm trying to use the example code in this app in mine, but am running into this error
server-0 (err): AssertionError: The model type must be a constructor server-0 (err): at Function.registry.getModelByType (/usr/local/lib/node_modules/loopback/lib/registry.js:286:3) server-0 (err): at PassportConfigurator.setupModels (/usr/local/lib/node_modules/loopback-component-passport/lib/passport-configurator.js:33:70) server-0 (err): at Object.<anonymous> (/opt/nodegloo/server/server.js:71:22) server-0 (err): at Module._compile (module.js:456:26) server-0 (err): at Object.Module._extensions..js (module.js:474:10) server-0 (err): at Module.load (module.js:356:32) server-0 (err): at Function.Module._load (module.js:312:12) server-0 (err): at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:187:23
this is in the passportConfigurator.setupModels() function
it seems when this is being called, app.models.user / userIdentity / userCredential are undefined and therefore causing the problem
Am I missing something, or is there a bug / mistake / setup problem ?
thanks