Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Http Interceptor #495

Open
Yann77 opened this issue Jun 26, 2019 · 2 comments
Open

Using Http Interceptor #495

Yann77 opened this issue Jun 26, 2019 · 2 comments

Comments

@Yann77
Copy link

Yann77 commented Jun 26, 2019

Hi !

I was wondering how to use my Custom HttpInterceptor with ngx-uploader. Since it is not using HttpClient but XMLHttpRequest directly, interception is nerver made. That would be useful in the case some JWT token validation needs to be done, etc.

Is it something plan ?

Best Regards,
Yannick

@zbagley
Copy link

zbagley commented Jul 16, 2019

XMLHttpRequest simply doesn't work well with interceptors, and that is likely why this repo's headers: { key: value } exists when building your upload request.

I use Authorization headers with a localstorage token, which should be standard:

  ngOnInit() {
    const token = localStorage.getItem('token');
    if (token) {
      this.authHeader = { Authorization: `bearer ${token}` };
    } else {
      this.authService.logout();
    }
  
  startUpload(): void {
    const event: UploadInput = {
      type: 'uploadAll',
      url: this.url,
      method: 'POST',
      data: { foo: 'bar' },
      headers: this.authHeader
    };

This feature likely won't be available unless Angular decides to build in support to HttpClientModule for XMLHttpRequest.

@Yann77
Copy link
Author

Yann77 commented Jul 16, 2019

Thanks for your answer ! I extracted most of my interceptor logic so I can reuse it while interacting with ngx-uploader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants