本文整理匯總了TypeScript中express.Request.isAuthenticated方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Request.isAuthenticated方法的具體用法?TypeScript Request.isAuthenticated怎麽用?TypeScript Request.isAuthenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類express.Request
的用法示例。
在下文中一共展示了Request.isAuthenticated方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
module.exports = function (req: Request, res: Response, next: any) {
// User is allowed, proceed to controller
var is_auth = req.isAuthenticated();
if (is_auth) return next();
// User is not allowed
return res.sendStatus(401);
};
示例2: getUser
export function getUser(req: Request, res: Response): void {
if (req.isAuthenticated()) {
const user = filterUserFieldsFromReqUser(req.user);
res.json(user);
}
else res.status(404).json({ message: "Account doesn't exists" });
}
示例3: authorize
public authorize (req: Request, res: Response, next: NextFunction){
if(!req.isAuthenticated()){
return res.redirect('/');
}
next();
}
示例4:
export let getForgot = (req: Request, res: Response) => {
if (req.isAuthenticated()) {
return res.redirect("/");
}
res.render("account/forgot", {
title: "Forgot Password"
});
};
示例5: next
export let isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
if (req.isAuthenticated()) {
return next();
}
res.redirect("/login");
};