mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-10 23:39:31 -05:00
22 lines
704 B
TypeScript
22 lines
704 B
TypeScript
import buildDebug from 'debug';
|
|
import { Response, Router } from 'express';
|
|
|
|
import { errorUtils } from '@verdaccio/core';
|
|
|
|
import { $NextFunctionVer, $RequestExtend } from '../types/custom';
|
|
|
|
const debug = buildDebug('verdaccio:api:user');
|
|
|
|
export default function (route: Router): void {
|
|
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'));
|
|
}
|
|
|
|
debug('whoami: response %o', username);
|
|
return next({ username: username });
|
|
});
|
|
}
|