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.
I tried two ways of doing a refresh flow in my application.
First one, using
Task.andThen
andTask.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 becausemakeTokenRequest
required a message, and didn't return aTask
or something that I could turn into aTask
, 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 calculateexpiresAt
usingexpiresIn
andTime.now
and store this info in Local Storage so I know if I have to refresh when opening the app. Ideally I would useTask.map2
to combine the result of the refresh request with the result ofTime.now
, and then store it, however,makeTokenRequest
is not aTask
so I cannot do this, so I have to handle the result ofTime.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.