fix auth bug

main
cogentapps 2023-07-04 19:25:27 +00:00
parent 2d95041970
commit 6ed206ccc8
1 changed files with 3 additions and 1 deletions

View File

@ -6,12 +6,14 @@ export default class SessionRequestHandler extends RequestHandler {
async handler(req: express.Request, res: express.Response) { async handler(req: express.Request, res: express.Response) {
const request = req as any; const request = req as any;
const authenticated = !!(request.oidc?.user?.sub || request.session?.passport?.user?.id);
const availableServiceNames = Object.keys(config.services || {}) const availableServiceNames = Object.keys(config.services || {})
.filter(key => { .filter(key => {
const serviceConfig = (config.services as any)?.[key]; const serviceConfig = (config.services as any)?.[key];
const apiKey = serviceConfig?.apiKey; const apiKey = serviceConfig?.apiKey;
const loginRequired = serviceConfig?.loginRequired ?? true; const loginRequired = serviceConfig?.loginRequired ?? true;
return apiKey && (!loginRequired || request.isAuthenticated()); return apiKey && (!loginRequired || authenticated);
}); });
if (request.oidc) { if (request.oidc) {