Last active
January 20, 2020 08:47
-
-
Save ngoclt/53c9abbfba0928cc10dd89e85bc968a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const refreshAuthLogic = (failedRequest) => { | |
const refreshToken = (response) => { | |
actions.auth.signInAsync.success(response); | |
actions.userSetting.saveUserSettingAsync.request({ | |
session: { uid: response.uid, token: response.token }, | |
}); | |
failedRequest.response.config.headers.Authorization = | |
'Bearer ' + response.token; | |
}; | |
const signInRequest = (params) => | |
signIn(params) | |
.then((response) => { | |
refreshToken(response); | |
Promise.resolve(); | |
}) | |
.catch((error) => { | |
console.log(error); | |
Promise.reject(); | |
}); | |
return getCredential() | |
.then((credentials) => { | |
const params = { | |
phone: credentials.username, | |
password: credentials.password, | |
}; | |
signInRequest(params); | |
}) | |
.catch((_) => { | |
const params = { uid: session.uid }; | |
signInRequest(params); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment