transistorsoft / background-geolocation-console

A field-testing & analysis server for the Background Geolocation plugin
MIT License
151 stars 157 forks source link

Updated documentation for basic params/auth set-up for device + org id? #132

Open adamlutz opened 2 years ago

adamlutz commented 2 years ago

First, thank you for getting me up and running in a matter of minutes with your software. I've got a react native background demo app up and running using class components (based of this sample code)

I also have the background-geolocation-console app up and running on Heroku. I can log data to it, however I'm running into similar issues that others have posted regarding not providing the correct parameters as to take advantage of the device filtering dropdown + solve the sql lite errors.

The logs look like this

2022-10-24T23:04:53.495996+00:00 app[web.1]: v1:location:create org:name UNKNOWN org:id undefined device:id undefined
2022-10-24T23:04:53.496109+00:00 app[web.1]: v1:location:create {} {"latitude":37.785834,"longitude":-122.406417,"data":"{\"coords\":{\"speed_accuracy\":-1,\"speed\":-1,\"longitude\":-122.406417,\"floor\":null,\"heading_accuracy\":-1,\"latitude\":37.785834,\"accuracy\":5,\"altitude_accuracy\":-1,\"altitude\":0,\"heading\":-1},\"extras\":{},\"mock\":true,\"is_moving\":false,\"event\":\"motionchange\",\"odometer\":62956.2,\"uuid\":\"61733BA4-F079-47D5-A1B2-FBF69789C8BE\",\"activity\":{\"type\":\"unknown\",\"confidence\":100},\"battery\":{\"level\":-1,\"is_charging\":false},\"timestamp\":\"2022-10-24T23:04:53.246Z\"}","recorded_at":"2022-10-24T23:04:53.246Z","created_at":"2022-10-24T23:04:53.493Z"}
2022-10-24T23:04:53.500741+00:00 app[web.1]: Executing (default): INSERT INTO `locations` (`id`,`latitude`,`longitude`,`data`,`recorded_at`,`created_at`) VALUES (NULL,$1,$2,$3,$4,$5);
2022-10-24T23:04:53.501385+00:00 app[web.1]: <!> Exception WHERE parameter "id" has invalid "undefined" value:  Error: WHERE parameter "id" has invalid "undefined" value

Based on other issues I've read and other comments, I've tried a few things to pass some of the filtering params through like,

1) passing params to ready() params: BackgroundGeolocation.transistorTrackerParams(device) -- my version of the lib says transistorTrackerParams is deprecated, and going this route doesn't make a difference (the code recommends using the authorizationToken approach here next).

2) BackgroundGeolocation.findOrCreateTransistorAuthorizationToken -- Unfortunately, I'm unable to create an authentication token going this route (I tried setting the SHARED_DASHBOARD and ADMIN_TOKEN env vars but still was unable to get a token from the server)

{"accessToken": "", "expires": -1, "refreshToken": "", "url": "https://xxxxxxxx.herokuapp.com"}

Wondering if there's something obvious I've overlooked and/or if there might be updated docs you could point me to that might help solve this? Thank you

christocracy commented 2 years ago

BackgroundGeolocation.transistorTrackerParams(device)

you don’t need this method.

see the plugin api docs TransistorAuthorizationToken

adamlutz commented 2 years ago

Thanks Chris.

Yeah I figured transistorTrackerParams was not needed and/or no longer supported. I did try the findOrCreateTransistorAuthorizationToken approach outlined in the api docs, and haven't had luck with it.

I have tried this a few different ways and get an empty access token from the console server: {"accessToken": "", "expires": -1, "refreshToken": "", "url": "https://xxxxxx.herokuapp.com"}

Server side, I have set the following env vars: SHARED_DASHBOARD=1, ADMIN_TOKEN, JWT_PUBLIC_KEY, and JWT_PRIVATE_KEY... none of these seem to make a difference. And given no token, I'm of course seeing Auth Bearer not found in the server logs:

2022-10-25T00:38:06.266486+00:00 heroku[router]: at=info method=POST path="/api/locations" host=xxxxx.herokuapp.com request_id=6a58ad2d-5a8c-4bc3-aaff-3907de5505ba fwd="98.61.210.86" dyno=web.1 connect=0ms service=16ms status=403 bytes=237 protocol=https
2022-10-25T00:38:06.260778+00:00 app[web.1]: Authorization Bearer not found Error: Authorization Bearer not found
2022-10-25T00:38:06.260792+00:00 app[web.1]: at file:///app/server/libs/utils.js:107:17
christocracy commented 2 years ago

Why are you not posting your exact code to `findOrCreateTransistorAuthorizationToken’?

adamlutz commented 2 years ago

here it is. I can post my entire test component as well if you'd like, but was trying not to overwhelm the thread here.

tracker_host = 'https://xxxxxx.herokuapp.com';
async configure() {
    this.setState({
      token:
          await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(
              'my-org',
              'my-username',
              this.tracker_host,
          ),
    });
}
siriussoftware commented 7 months ago

and....you got the exact code. Where is the answeer