Cannot read property getGroups of undefined
Closed this issue · 4 comments
Not exactly sure whats going on here but I have a feeling it's tied to the fact that there may not be any groups associated to a directory.
How it all started was me configuring a Google social login directory. I mapped the directory to the application and all seemed well.
Later, when I ran the application locally, I am consistently failing on initializing the Stormpath communication piece(never gets to stormpath.ready
).
//application.js
// ...
application.use(stormpath.init(application, stormpathConfiguration));
application.on('stormpath.ready', () => {
application.listen(port, (error) => {
if (error) {
logger.error(error);
}
open(`http://localhost:${port}`);
logger.info(`Serving API from ${host}:${port}`);
});
});
//stormpathConfiguration.js
/* eslint-disable no-process-env */
const configuration = {
web: {
produces: ['application/json'],
me: {
expand: {
customData: true
}
}
},
// For more information on caching options and settings
// https://docs.stormpath.com/nodejs/product-guide/latest/configuration.html
cacheOptions: {
store: 'redis',
connection: {
host: process.env.CACHE_HOST || 'localhost',
port: process.env.CACHE_PORT || 6379
}
},
register: {
form: {
fields: {
color: {
enabled: true,
label: 'Color',
placeholder: 'blue',
type: 'text'
}
}
}
}
};
export default configuration;
TypeError: Cannot read property 'getGroup' of undefined
at /Users/oshalygin/dev/Atom/node_modules/stormpath-config/lib/strategy/EnrichIntegrationFromRemoteConfigStrategy.js:155:28
at Object.drain (/Users/oshalygin/dev/Atom/node_modules/stormpath/lib/resource/CollectionResource.js:1044:9)
I did a little more research on the EnrichIntegrationFromRemoteConfigStrategy:
EnrichIntegrationFromRemoteConfigStrategy.prototype._resolveDirectoryHref = function (app, callback) {
var outerScope = this;
app.getAccountStoreMappings(function(err, mappings) {
if (err) {
return callback(err);
}
mappings.detect(function(mapping, detectCallback) {
detectCallback(mapping.isDefaultAccountStore);
}, function(defaultMapping) {
if (defaultMapping) {
var href = defaultMapping.accountStore.href;
if (href.match(/directories/)) {
return callback(null, href);
}
if (href.match(/group/)) {
console.log(outerScope); //added this to see whats going on
console.log(outerScope.client); //added this to see whats going on
outerScope.client.getGroup(href, function(err, group) {
return callback(err, group && group.directory.href);
});
} else {
return callback(null, null);
}
} else {
return callback(null, null);
}
});
});
};
I added a few breakpoints and logs and
console.log(outerScope) => EnrichIntegrationFromRemoteConfigStrategy { clientFactory: [Function: ClientFactory] }
console.log(outerScope.client) => obviously undefined.
I have a feeling that this commit fixes the problem.
stormpath/stormpath-node-config@4946166
Going to upgrade my express-stormpath version to 3.1.8
UPDATE: that didn't work.
Okay upgrading express-stormpath
to version 3.1.8
didn't do it, so I went to look at the stormpath-config npm module and noticed that this version didnt have the commit from @robertjd
stormpath/stormpath-node-config@4946166
So I manually added that line and re-ran it and everything is back to perfection.
I'll make a PR shortly
Addressed as part of a release