-
Notifications
You must be signed in to change notification settings - Fork 426
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
How to update config after refresh token. #710
Comments
I'm also interested in this - @panda919 am I correct in saying that in the general sense the question is: If you already launched your app and have this plugin running, what is the best way to dynamically alter it's config? My case is that I want extra user information available in the "extras" but I only have it available in certain situations and definitely only after app launch. If I'm able to get that info I'd like to alter the info included in extras and have that change take affect I suppose I/we could do a stop/config/ready-with-reset ? (carefully checking state even) |
Actually, I didn't find solution for update config dynamically !!! |
did you try stop/config-with-reset/ready ? basically re-cycling the plugin ? I haven't tried it yet but this was going to be my test |
I didn't not stop. |
BackgroundGeolocation.setConfig({ |
Yes, #setConfig. No need to #stop. Listen to #onHttp for 401 as your cue to change your token. Be sure to do that in your HeadlessTask, as well. |
BackgroundGeolocation.onHttp(httpEvent => {
//console.warn('[http] ', httpEvent.success, httpEvent.status);
let statusCode = parseInt (parseInt(httpEvent.status) / 100 );
if(statusCode == 4){
======================
// get new auth token
=====================
let headers = {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " +--new token---
};
BackgroundGeolocation.setConfig({
headers: headers,
reset: true,
});
BackgroundGeolocation.sync();
}); this is my source. |
thanks. but pls check above my code snipet. what is wrong? |
BackgroundGeolocation.setConfig({
headers: headers,
//reset: true, // <-- reset doesn't apply to setConfig. remove.
}).then((state) => {
console.log('- Updated headers: ', state.headers);
BackgroundGeolocation.sync();
}); The plugin's methods are asynchronous. You can't execute #sync until #setConfig completes. |
ah, got it. |
This should also work: BackgroundGeolocation.onHttp(httpEvent => async {
await BackgroundGeolocation.setConfig({headers: headers});
BackgroundGeolocation.sync();
}); |
awesome this will help me too, and I likely would have also forgotten async - thanks @christocracy |
thanks very much |
@mikehardy you can't change |
Yes - until you code up react-native-time-travel I'll have (from my perspective) incomplete data in the past but that's fine - with uids you only need one visible strobe to link things up and that's my use case, so works for me just fine |
@christocracy when http sync happens in the background (without app running, swiped up to shut down), will As recommended in example from README I'm calling What is recommended approach here? |
On Android, of course not. That's what Android Headless Mode is for. |
@christocracy
|
In
Correct. The Scheduler is a bot that automatically calls
Yes, of course. The HTTP Service is an independent entity that operates upon the SQLite database, selecting records, executing HTTP requests and deleting records when your server says |
meaning, stopSchedule function call stop() function automatically implicty? |
Why don't you experiment? No, it only stops the schedule bot.
|
I am meaning. BackgroundGeolocation.start(() => {
BackgroundGeolocation.startSchedule();
});
BackgroundGeolocation.stopSchedule(() => {
BackgroundGeolocation.stop();
}); this code is correct? |
If you have a schedule configured, why would you explicitly call As for the |
Your Environment
react-native -v
): 0.55.4Expected Behavior
Actual Behavior
Context
I used JWT troken auth.
When token is expired, i get new auth token and update BackgroundGeolocation 's config and call sync() function.
BackgroundGeolocation.setConfig({
headers: ------,//new auth token header
reset: true,
});
this.sync();
But, I got 401 error yet.
What's wrong?
Debug logs
The text was updated successfully, but these errors were encountered: