我使用下面的函式將recaptcha v3附加到Http請求。
@Injectable()
export class RecaptchaInterceptor implements HttpInterceptor {
constructor(private recaptchaService: ReCaptchaService) { }
intercept(httpRequest: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return fromPromise(this.recaptchaService.execute({ action: 'login' }))
.pipe(switchMap(token => {
const headers = httpRequest.headers
.set('recaptcha', token)
const reqClone = httpRequest.clone({
headers
});
return next.handle(reqClone);
}));
}
在 localhost 這作業正常,但由于某種原因,發布后我收到以下錯誤:
Uncaught (in promise): TypeError: (0 , x.fromPromise) is not a function TypeError: (0 , x.fromPromise) is not a function
有什么建議?非常感謝!
uj5u.com熱心網友回復:
您可以使用 from 而不是 fromPromise 因為我認為您使用的是 rxjs 6
import { from } from 'rxjs';
...
return from(this.recaptchaService.execute({ action: 'login' }))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/320960.html
