marklogic-community / slush-marklogic-node

Slush generator for a MarkLogic/node project
https://github.com/marklogic-community/slush-marklogic-node/wiki
Other
40 stars 28 forks source link

Every reload of the '/search' requires the user to log-in again #529

Closed sashamitrovich closed 6 years ago

sashamitrovich commented 6 years ago

This happens with MarkLogic 9.0-3.1

grtjn commented 6 years ago

That has been bothering me a lot since 9.0-3 too! I have been digging in, and I think I found the culprit. It goes wrong at the initial call to /api/user/status after a browser reload. At that point the middle-tier is initialized, and authenticator is prepared. Unfortunately, the route for /api/user/status passes in the wrong path to calculate the auth header, so it gets rejected by ML since 9.0-3.

This and following line:

https://github.com/marklogic-community/slush-marklogic-node/blob/master/app/templates/node-server/routes.js#L49

needs to be replaced with:

var passportUser = req.session.passport.user;
var path = '/v1/documents?uri=/api/users/' + passportUser.username + '.json';

After that it all runs as before!

sashamitrovich commented 6 years ago

Verified, the fix works on ML 9.0-3.1! (This really helps preventing insanity from constant logging in, thanks!)