opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://opensrp.io
Apache License 2.0
58 stars 59 forks source link

Login error with Correct credentials #3632

Closed madrinekariuki closed 4 days ago

madrinekariuki commented 1 week ago

Apk: engage-preview-20-nov-2024.apk Device: Nokia G22 android 14 && samsung A12android 11

Describe the bug When one tries to login to the apk with the correct credentials , the app fails to login the first time and one has to click the login button again for a successful login. the error being thrown is Login error: Failed to fetch user details.

To Reproduce

  1. install the app
  2. input the correct username and password
  3. click on login.

Expected behavior If the credentials are correct, the app should login on the first attempt.

Screenshots

https://github.com/user-attachments/assets/c94a87b2-0a89-4e31-af27-d02c07c0d107

see below 401 error response:

2024-11-21 17:39:49.557 20335-20478 okhttp.OkHttpClient     org.smartregister.opensrp.engage     I  --> POST https://keycloak.smartregister.org/auth/realms/engage-columbia-preview/protocol/openid-connect/token (94-byte body)
2024-11-21 17:39:49.638 20335-20478 TrafficStats            org.smartregister.opensrp.engage     D  tagSocket(153) with statsTag=0xffffffff, statsUid=-1
2024-11-21 17:39:49.655 20335-20335 InputEventReceiver      org.smartregister.opensrp.engage     D  channel '915185b org.smartregister.opensrp.engage/org.smartregister.fhircore.quest.ui.login.LoginActivity (client)' ~ reportTimeline
2024-11-21 17:39:50.339 20335-20478 okhttp.OkHttpClient     org.smartregister.opensrp.engage     I  <-- 200 https://keycloak.smartregister.org/auth/realms/engage-columbia-preview/protocol/openid-connect/token (780ms, 6860-byte body)
2024-11-21 17:39:50.476 20335-20488 okhttp.OkHttpClient     org.smartregister.opensrp.engage     I  --> GET https://keycloak.smartregister.org/auth/realms/engage-columbia-preview/protocol/openid-connect/userinfo
2024-11-21 17:39:50.482 20335-20488 TrafficStats            org.smartregister.opensrp.engage     D  tagSocket(157) with statsTag=0xffffffff, statsUid=-1
2024-11-21 17:39:51.194 20335-20488 okhttp.OkHttpClient     org.smartregister.opensrp.engage     I  <-- 401 https://keycloak.smartregister.org/auth/realms/engage-columbia-preview/protocol/openid-connect/userinfo (717ms, 0-byte body)
2024-11-21 17:39:51.479 20335-20342 .opensrp.engage         org.smartregister.opensrp.engage     W  Cleared Reference was only reachable from finalizer (only reported once)
2024-11-21 17:39:51.549 20335-20375 TrafficStats            org.smartregister.opensrp.engage     D  tagSocket(159) with statsTag=0xffffffff, statsUid=-1
---------------------------- PROCESS STARTED (20487) for package org.smartregister.opensrp.ecbis_training ----------------------------
2024-11-21 17:39:51.610 20487-20487 CheckTime               org...gister.opensrp.ecbis_training  W  App running slow: Executing handleBindApplication : callApplicationOnCreate took 657ms
2024-11-21 17:39:51.768 20487-20487 Choreographer           org...gister.opensrp.ecbis_training  I  Skipped 73 frames!  The application may be doing too much work on its main thread.
2024-11-21 17:39:52.086 20335-20342 .opensrp.engage         org.smartregister.opensrp.engage     I  Background concurrent mark compact GC freed 35MB AllocSpace bytes, 331(25MB) LOS objects, 34% free, 89MB/137MB, paused 1.601ms,5.780ms total 1.117s
2024-11-21 17:39:52.133 20335-20344 System                  org.smartregister.opensrp.engage     W  A resource failed to call release. 
2024-11-21 17:39:54.215 20335-20375 TrafficStats            org.smartregister.opensrp.engage     D  tagSocket(148) with statsTag=0xffffffff, statsUid=-1
2024-11-21 17:39:57.112 20487-21327 ProfileInstaller        org...gister.opensrp.ecbis_training  D  Installing profile for org.smartregister.opensrp.ecbis_training
2024-11-21 17:40:00.864 20335-20335 Choreographer           org.smartregister.opensrp.engage     W  Frame time is 0.017052 ms in the future!  Check that graphics HAL is generating vsync timestamps using the correct timebase.
---------------------------- PROCESS ENDED (20487) for package org.smartregister.opensrp.ecbis_training ----------------------------
madrinekariuki commented 1 week ago

issue related to #219

ndegwamartin commented 4 days ago

Did some investigations on this - this happens because the initial access token fetch and the credentials persistence and the subsequent data fetch happen asynchronously. i.e. by the time the Practitioner data fetch details is being triggered the credentials have not been saved yet so that request will not have an access token available.

Usually it is available at the second try which is why it works then.

LZRS commented 4 days ago

There's this PR, that would probably fix it