通过Angular HttpClientModule启用CSRF,错误:TS2552:找不到名称HttpXsrfInterceptor

问题描述 投票:0回答:1

来自前端初学者的问题。我想将 csrf 令牌添加到前端应用程序中的某些请求中。该应用程序在版本 12.2.17 中使用 Angular。我遵循 Angular 文档中的说明:https://angular.io/api/common/http/HttpClientXsrfModule

在代码中我添加拦截器如下:

import {HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule  } from "@angular/common/http";


imports: [
        ...
        HttpClientXsrfModule
    ],
providers: [
         ...
        { provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true }
    ],

当我这样做时,带有“HttpXsrfInterceptor”的行会触发 IntelliJ 中的错误工具提示:

TS2552: Cannot find name  HttpXsrfInterceptor . Did you mean  HTTP_INTERCEPTORS ?

我应该更改什么才能正确配置 HttpXsrfInterceptor?

angular typescript csrf angular-http-interceptors csrf-token
1个回答
0
投票

请更新以下行!

import {HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule, HttpXsrfInterceptor } from "@angular/common/http";
© www.soinside.com 2019 - 2024. All rights reserved.