pip-services3-rpc-node
Version:
Remote procedure calls for Pip.Services in Node.js
32 lines (26 loc) • 887 B
text/typescript
/** @module auth */
const _ = require('lodash');
import { UnauthorizedException } from 'pip-services3-commons-node';
import { HttpResponseSender } from '../services/HttpResponseSender';
export class BasicAuthorizer {
public anybody(): (req: any, res: any, next: () => void) => void {
return (req, res, next) => {
next();
};
}
public signed(): (req: any, res: any, next: () => void) => void {
return (req, res, next) => {
if (req.user == null) {
HttpResponseSender.sendError(
req, res,
new UnauthorizedException(
null, 'NOT_SIGNED',
'User must be signed in to perform this operation'
).withStatus(401)
);
} else {
next();
}
};
}
}