mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
implement a retry mechanism over a second
This commit is contained in:
@@ -74,32 +74,34 @@ Meteor.startup(() => {
|
||||
Accounts.oauth.tryLoginAfterPopupClosed = (
|
||||
credentialToken,
|
||||
callback,
|
||||
shouldRetry = true
|
||||
timeout = 1000
|
||||
) => {
|
||||
const credentialSecret =
|
||||
OAuth._retrieveCredentialSecret(credentialToken);
|
||||
let startTime = Date.now();
|
||||
let intervalId;
|
||||
const checkForCredentialSecret = (clearInterval = false) => {
|
||||
const credentialSecret = OAuth._retrieveCredentialSecret(credentialToken);
|
||||
if (clearInterval || credentialSecret) {
|
||||
Meteor.clearInterval(intervalId);
|
||||
Accounts.callLoginMethod({
|
||||
methodArguments: [{ oauth: { credentialToken, credentialSecret } }],
|
||||
userCallback: callback ? err => callback(convertError(err)) : () => {},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Check immediately
|
||||
checkForCredentialSecret();
|
||||
|
||||
// Then check on an interval
|
||||
// In some case the function OAuth._retrieveCredentialSecret() can return null, because the local storage might not
|
||||
// be ready. So we retry after a timeout.
|
||||
|
||||
if (!credentialSecret && shouldRetry) {
|
||||
Meteor.setTimeout(
|
||||
() =>
|
||||
Accounts.oauth.tryLoginAfterPopupClosed(
|
||||
credentialToken,
|
||||
callback,
|
||||
false
|
||||
),
|
||||
500
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// continue with the rest of the function
|
||||
Accounts.callLoginMethod({
|
||||
methodArguments: [{ oauth: { credentialToken, credentialSecret } }],
|
||||
userCallback: callback ? err => callback(convertError(err)) : () => {},
|
||||
});
|
||||
intervalId = Meteor.setInterval(() => {
|
||||
if (Date.now() - startTime > timeout) {
|
||||
checkForCredentialSecret(true);
|
||||
} else {
|
||||
checkForCredentialSecret();
|
||||
}
|
||||
}, 250);
|
||||
};
|
||||
|
||||
Accounts.oauth.credentialRequestCompleteHandler = callback =>
|
||||
|
||||
@@ -97,7 +97,6 @@ const getTokenResponse = async (query) => {
|
||||
.then((res) => res.json())
|
||||
.then(data => {
|
||||
const fbAccessToken = data.access_token;
|
||||
console.log("-> fbAccessToken", fbAccessToken);
|
||||
const fbExpires = data.expires_in;
|
||||
if (!fbAccessToken) {
|
||||
throw new Error("Failed to complete OAuth handshake with facebook " +
|
||||
|
||||
Reference in New Issue
Block a user