getCognitoInstance() returns the login page url of hosted UI of cognito.
validateUrlAndRedirectCognito() redirects to that url.
Since the value of '_userProperty' is 'user', req.isAuthenticated() should return true after authentication.
Please help me with what is wrong in this code.
req.isAuthenticated() is returning false even after authenticating with AWS cognito.
The function which I am using for adding login routes is:
addAuthenticationRoutesCognito: function (app) {
}
And for checking if the request is authenticated I am using:
function ensureAuthenticatedCognito(req, res, next) { console.log("is request authenticated ? " + req.isAuthenticated()); console.log("original ULR = " + req.originalUrl); console.log('req====',req);
if (!req.isAuthenticated()) {
let cognitoObj = authManager.getCognitoInstance(); // console.log('cognitoObj.loginUrl==', cognitoObj.loginUrl); authManager.validateUrlAndRedirectCognito(cognitoObj.loginUrl, req, res); // return next(); } else { return next(); } }
The _passport object printed inside res is:
_passport: { instance: Authenticator { _key: 'passport', _strategies: [Object], _serializers: [Array], _deserializers: [Array], _infoTransformers: [], _framework: [Object], _userProperty: 'user', Authenticator: [Function: Authenticator], Passport: [Function: Authenticator], Strategy: [Function], strategies: [Object] } }
getCognitoInstance() returns the login page url of hosted UI of cognito. validateUrlAndRedirectCognito() redirects to that url.
Since the value of '_userProperty' is 'user', req.isAuthenticated() should return true after authentication. Please help me with what is wrong in this code.