Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function userInfoMiddleware(incomingRequest, outgoingResponse, next) {
if (incomingRequest.session && incomingRequest.session.userSession) {
Promise.all([
getUser({ authentication: incomingRequest.session.userSession }),
getSelf({ authentication: incomingRequest.session.userSession })
]).then(([userInfo, orgInfo]) => {
// add information to the request so the next middleware can access it
incomingRequest.session.userInfo = userInfo;
incomingRequest.session.orgInfo = orgInfo;
next(); // run the next middleware
});
} else {
next(); // run the next middleware
}
}
public async getGroups() : Promise {
await this.authenticate();
return getUser({
username: this.authentication.username,
authentication: this.authentication,
portal: this.restURL,
}).then(user => user.groups || []);
}