OkHTTP Interceptor with OTP

Viewed 44

High Level -

I have a use case where I need to intercept the response and open the OTP screen. When OTP entered then re-try the same API with the OTP entered in the headers.

Detailed Explanation -

Let's suppose I make an API request from screen A, and that API returned 401 so I opened the OTP screen and an OTP is sent to user SIM. When OTP entered I call the same API by adding OTP entered on it. When the re-call gives success I open the next screen.

Below is the flow needed for the use case. Flow Required

Approach Taken -

So I used an OTP interceptor which opens the OTP screen with all the details required to make a retry call (like headers, body, requests, etc.). And I created a registry which sits on top.

Registry is something which contains a Flow and Screen A listens to that. And OTP screen is what emits the new retry API response. And whenever in Screen A a new value is collected in the flow I call the next method which is needed to move forward.

This flow has some drawback and need to know is there any better approach were any journey I need OTP all the OTP screen and retry function is done without letting the journey know about this.

0 Answers
Related