Skip to content

Instantly share code, notes, and snippets.

@ngoclt
Last active January 20, 2020 08:47
Show Gist options
  • Save ngoclt/53c9abbfba0928cc10dd89e85bc968a1 to your computer and use it in GitHub Desktop.
Save ngoclt/53c9abbfba0928cc10dd89e85bc968a1 to your computer and use it in GitHub Desktop.
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