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

Interceptor for nativescript-background-http requests #195

Open
progressify opened this issue Jan 2, 2019 · 4 comments
Open

Interceptor for nativescript-background-http requests #195

progressify opened this issue Jan 2, 2019 · 4 comments

Comments

@progressify
Copy link

Hi,
In my project, I have integrated JWT authentication with an interceptor for all HTTP request.
Exists a method for intercept the requests of nativescript-background-http?

Which platform(s) does your issue occur on?

  • Android Pie
  • Device: Google Pixel 2 XL

Please, provide the following version numbers that your issue occurs with:

  • CLI: (run tns --version to fetch it)
    5.0.1
  • Cross-platform modules: (check the 'version' attribute in the
    node_modules/tns-core-modules/package.json file in your project)
    "tns-core-modules": "^5.0.2",
  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the package.json file of your project)
    "tns-ios": {
    "version": "4.2.0"
    },
    "tns-android": {
    "version": "5.0.0"
    }
  • Plugin(s): (look for the version numbers in the package.json file of your
    project and paste your dependencies and devDependencies here:
    "nativescript-background-http": "^3.3.1",

This is the code I have used to intercept all the http requests:

app.module.ts

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

...
...

@NgModule({
    bootstrap: [
        ...
    ],
    imports: [
        ...
    ],
    declarations: [
       ...
    ],
    providers: [
        ...
        {
            provide : HTTP_INTERCEPTORS,
            useClass: RequestInterceptorService,
            multi: true
        }
    ],
    schemas: [
        ...
    ]
})
@zbranzov
Copy link
Contributor

zbranzov commented Jan 4, 2019

Hi @progressify ,
Do you have a sample demo of what you are trying to achieve? Have you tried to intercept the requests using already integrated HTTP_INTERCEPTORS?
If you question is whether the plugin has such interception functionality, I would say No. So I would suggest you using some third party one.

@progressify
Copy link
Author

Hi, I have read and used this tutorial to implement JWT, intercept and refresh token logic:
https://www.intertech.com/Blog/angular-4-tutorial-handling-refresh-token-with-new-httpinterceptor/

but seem to work only with the HTTP request from '@angular/common/http', not from nativescript-background-http

@ForzaMark
Copy link

ForzaMark commented Apr 7, 2020

to have a workaround you can add your Authorization header manually like
let request = { url: "urlToPost", method: "POST", headers: { "Authorization": "Bearer ${getToken()}" }, };

@jbouloux1
Copy link

Exactly the same issue here. When I try your workaround, the Authorization header isn't sent to server.

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

No branches or pull requests

6 participants