本文整理汇总了TypeScript中response/guards/guardFactory.GuardFactory.createAsync方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GuardFactory.createAsync方法的具体用法?TypeScript GuardFactory.createAsync怎么用?TypeScript GuardFactory.createAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类response/guards/guardFactory.GuardFactory
的用法示例。
在下文中一共展示了GuardFactory.createAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: checkConsentedAlready
function checkConsentedAlready (): express.RequestHandler {
return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
const user: User = res.locals.user
const roles = await claimStoreClient.retrieveUserRoles(user)
return roles && !roles.some(role => role.includes('cmc-new-features-consent'))
}, (req: express.Request, res: express.Response): void => {
res.redirect(ClaimPaths.taskListPage.uri)
})
}
示例2: requestHandler
static requestHandler (): express.RequestHandler {
return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
if (!FeatureToggles.isEnabled('newFeaturesConsent')) {
return true
}
const user: User = res.locals.user
const roles = await claimStoreClient.retrieveUserRoles(user)
return roles.length !== 0 && roles.some(role => role.includes('cmc-new-features-consent'))
}, (req: express.Request, res: express.Response): void => {
res.redirect(ClaimPaths.newFeaturesConsentPage.uri)
})
}
示例3: requestHandler
/**
* Makes sure that eligibility check has passed prior accessing protected pages. The eligibility is assessed by
* checking whether draft has been marked as eligible or whether eligible cookie exists. If none of the conditions
* is met then user is redirected to eligibility index page, otherwise request is let through as is.
*
* @returns {express.RequestHandler} - request handler middleware
*/
static requestHandler (): express.RequestHandler {
return GuardFactory.createAsync(async (req: express.Request, res: express.Response) => {
const draft: Draft<DraftClaim> = res.locals.claimDraft
if (draft.document.eligibility) {
return true
}
const eligibility = eligibilityStore.read(req, res)
if (eligibility.eligible) {
await this.markDraftEligible(draft, res.locals.user)
eligibilityStore.clear(req, res)
return true
}
return false
}, (req: express.Request, res: express.Response): void => {
res.redirect(EligibilityPaths.startPage.uri)
})
}