Skip to content

Commit

Permalink
Improve auth error message, encourage reauth.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbleigh committed Mar 9, 2017
1 parent 0b3649b commit 92c5c89
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions lib/auth.js
Expand Up @@ -20,6 +20,12 @@ var scopes = require('./scopes');

portfinder.basePort = 9005;

var INVALID_CREDENTIAL_ERROR = new FirebaseError(
'Authentication Error: Your credentials are no longer valid. Please run ' + chalk.bold('firebase login --reauth') + '\n\n' +
'For CI servers and headless environments, generate a new token with ' + chalk.bold('firebase login:ci'),
{exit: 1}
);

var FIFTEEN_MINUTES_IN_MS = 15 * 60 * 1000;
var SCOPES = [
scopes.EMAIL,
Expand Down Expand Up @@ -66,18 +72,14 @@ var _getTokensFromAuthorizationCode = function(code, callbackUrl) {
}
}).then(function(res) {
if (!_.has(res, 'body.access_token') && !_.has(res, 'body.refresh_token')) {
throw new FirebaseError('Authentication Error.', {
exit: 1
});
throw INVALID_CREDENTIAL_ERROR;
}
lastAccessToken = _.assign({
expires_at: Date.now() + res.body.expires_in * 1000
}, res.body);
return lastAccessToken;
}, function() {
throw new FirebaseError('Authentication Error.', {
exit: 1
});
throw INVALID_CREDENTIAL_ERROR;
});
};

Expand Down Expand Up @@ -214,9 +216,7 @@ var _refreshAccessToken = function(refreshToken, authScopes) {
}
}).then(function(res) {
if (!_.isString(res.body.access_token)) {
throw new FirebaseError('Authentication Error.', {
exit: 1
});
throw INVALID_CREDENTIAL_ERROR;
}
lastAccessToken = _.assign({
expires_at: Date.now() + res.body.expires_in * 1000,
Expand All @@ -239,16 +239,7 @@ var _refreshAccessToken = function(refreshToken, authScopes) {
);
}

if (err.message === 'invalid_grant') {
_logoutCurrentSession(refreshToken);
throw new FirebaseError('Your refresh token has been revoked, please run ' +
chalk.bold('firebase login') + ' to obtain a new one.', {
exit: 1
});
}
throw new FirebaseError('Authentication Error.', {
exit: 1
});
throw INVALID_CREDENTIAL_ERROR;
});
};

Expand Down

0 comments on commit 92c5c89

Please sign in to comment.