2020-10-03 05:47:04 -07:00
|
|
|
import buildDebug from 'debug';
|
2021-10-29 17:33:05 +02:00
|
|
|
import { Response, Router } from 'express';
|
|
|
|
|
2022-07-29 20:51:45 +02:00
|
|
|
import { errorUtils } from '@verdaccio/core';
|
|
|
|
|
2021-10-29 17:33:05 +02:00
|
|
|
import { $NextFunctionVer, $RequestExtend } from '../types/custom';
|
2020-10-03 05:47:04 -07:00
|
|
|
|
|
|
|
const debug = buildDebug('verdaccio:api:user');
|
2019-07-16 08:40:01 +02:00
|
|
|
|
2021-03-14 08:42:46 +01:00
|
|
|
export default function (route: Router): void {
|
2022-07-29 20:51:45 +02:00
|
|
|
route.get('/-/whoami', (req: $RequestExtend, _res: Response, next: $NextFunctionVer): any => {
|
|
|
|
// remote_user is set by the auth middleware
|
|
|
|
const username = req?.remote_user?.name;
|
|
|
|
if (!username) {
|
|
|
|
debug('whoami: user not found');
|
|
|
|
return next(errorUtils.getUnauthorized('Unauthorized'));
|
2019-07-16 08:40:01 +02:00
|
|
|
}
|
2020-10-03 05:47:04 -07:00
|
|
|
|
|
|
|
debug('whoami: response %o', username);
|
|
|
|
return next({ username: username });
|
2021-03-14 08:42:46 +01:00
|
|
|
});
|
2019-07-16 08:40:01 +02:00
|
|
|
}
|