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

Add makeTokenRequest version that doesn't require toMsg as a parameter and returns a Task instead #28

Open
adrianbunea opened this issue Jun 7, 2021 · 0 comments

Comments

@adrianbunea
Copy link

I tried two ways of doing a refresh flow in my application.

First one, using Task.andThen and Task.onError, I wanted to attempt a request, refresh if the request failed with 401 and retry the request afterwards with the new token, and this would ideally only require one update cycle because the task would do all these things in one go behind the scenes, but I couldn't because makeTokenRequest required a message, and didn't return a Task or something that I could turn into a Task, so I couldn't make a reusable request wrapper.

The second way was to receive the expiresIn, schedule a new refresh in that time, and calculate expiresAt using expiresIn and Time.now and store this info in Local Storage so I know if I have to refresh when opening the app. Ideally I would use Task.map2 to combine the result of the refresh request with the result of Time.now, and then store it, however, makeTokenRequest is not a Task so I cannot do this, so I have to handle the result of Time.now into a separate update cycle, which makes this less reusable as well.

In both cases, I felt that requiring toMsg and not returning a Task made this impossible to compose, which would be very useful. Maybe there is a way I don't know of yet, so I am open to ideas, but I would like to know your opinion about this request.

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

No branches or pull requests

1 participant