Created
May 10, 2021 14:33
-
-
Save sunnymopada/88ae297d3a3387034b518ccaba848324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lass AuthStore { | |
refreshAuthTokensPromise:Type | |
authService:Type | |
constructor(authService) { | |
this.authService = authService | |
this.initAuthStore() | |
} | |
@action.bound | |
initAuthStore(): void { | |
this.refreshAuthTokensPromise = undefined | |
} | |
@action.bound | |
setRefreshAccessTokens(response: Tokens): void { | |
//Other code | |
this.refreshAuthTokensPromise = undefined | |
} | |
@action.bound | |
refreshAuthTokensAPI( | |
requestObject: RefreshAuthTokensRequest, | |
onSuccess: Function = (): void => {}, | |
onFailure: Function = (): void => {} | |
): any { | |
if (this.refreshAuthTokensPromise) { | |
return this.refreshAuthTokensPromise | |
} | |
this.refreshAuthTokensPromise = this.authService.refreshAuthTokensAPI( | |
requestObject | |
) | |
return bindPromiseWithOnSuccess(this.refreshAuthTokensPromise) | |
.to(this.setRefreshAccessTokensStatus, response => { | |
this.setRefreshAccessTokens(response as Tokens) | |
onSuccess() | |
}) | |
.catch(err => { | |
this.setRefreshAccessTokensError(err) | |
onFailure() | |
}) | |
} | |
} | |
export default AuthStore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment