本文整理汇总了TypeScript中composable-middleware.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hasRole
/**
* Checks if the user role meets the minimum requirements of the route
*/
public static hasRole(roleRequired: string) {
if (!roleRequired) {
throw new Error('Required role needs to be set');
}
var meetsRequirements = (req: express.Request, res: express.Response, next: Function) => {
if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
next();
}
else {
res.send(403);
}
}
return compose()
.use(AuthService.isAuthenticated())
.use(meetsRequirements);
}
示例2: isAuthenticated
export function isAuthenticated() {
return compose()
// Validate jwt
.use((req, res, next) => {
// allow access_token to be passed through query parameter as well
if (req.query && req.query.hasOwnProperty('access_token')) {
req.headers.authorization = 'Bearer ' + req.query.access_token;
}
return validateJwt(req, res, next);
})
// Attach user to request
.use((req, res, next) => {
return User.findById(req.user.id)
.then(user => {
if (!user) {
return res.status(401).json({ message: 'Invalid Token' });
}
req.user = user;
next();
// runnaway promise to remove node warning
return null;
})
.catch(err => next(err));
});
}
示例3: isAuthenticated
export function isAuthenticated() {
return compose()
// Validate jwt
.use((req, res, next) => {
// allow access_token to be passed through query parameter as well
if (req.query && req.query.hasOwnProperty('access_token')) {
req.headers.authorization = 'Bearer ' + req.query.access_token;
}
return validateJwt(req, res, next);
})
// Attach user to request
.use((req, res, next) => {
let user;
return UserModel.userByEmail(req.user.email)
.then(result => {
user = result.rows[0];
if (!user || user > 1)
res.status(401).json({ message: 'Invalid Token' });
req.user = user;
next();
})
.catch(err => next(err));
});
}
示例4: hasRole
/**
* Checks if the user role meets the minimum requirements of the route
*/
static hasRole(roleRequired) {
if (!roleRequired) throw new Error('Required role needs to be set');
return compose()
.use(AuthService.isAuthenticated())
.use(function meetsRequirements(req, res, next) {
if (config.userRoles.indexOf(req.user.role) >= config.userRoles.indexOf(roleRequired)) {
next();
}
else {
res.status(200).json({status: 'FORBIDDEN'});
}
});
}
示例5: hasRole
export function hasRole(roleRequired) {
if (!roleRequired) {
throw new Error('Required role needs to be set');
}
return compose()
.use(isAuthenticated())
.use(function meetsRequirements(req, res, next) {
if (config.userRoles.indexOf(req.user.role) >=
config.userRoles.indexOf(roleRequired)) {
next();
} else {
res.status(403).send('Forbidden');
}
});
}
示例6: compose
isAuthenticated: function () {
return compose()
.use(function(req, res, next) {
validateJwt(req, res, next);
})
.use(function(req, res, next) {
User.findById(req.user._id, function (err, user) {
if (err)
return next(err);
if (!user)
return res.send(401);
req.user = user;
next();
});
});
},
示例7: isAuthenticated
/**
* Attaches the user object to the request if authenticated
* Otherwise returns 403
*/
public static isAuthenticated() {
return compose()
// Validate jwt
.use(function(req, res, next) {
// allow access_token to be passed through query parameter as well
if(req.query && req.query.hasOwnProperty('access_token')) {
req.headers.authorization = 'Bearer ' + req.query.access_token;
}
validateJwt(req, res, next);
})
// Attach user to request
.use(function(req, res, next) {
user.Model.findById(req.user._id, function (err, user) {
if (err) return next(err);
if (!user) return res.send(401);
req.user = user;
next();
});
});
}