當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript GuardFactory.createAsync方法代碼示例

本文整理匯總了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)
  })
}
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:10,代碼來源:new-features-consent.ts

示例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)
    })
  }
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:14,代碼來源:newFeaturesConsentGuard.ts

示例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)
    })
  }
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:26,代碼來源:claimEligibilityGuard.ts


注:本文中的response/guards/guardFactory.GuardFactory.createAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。