@capawesome/cli
Version:
The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.
20 lines (19 loc) • 800 B
JavaScript
import userConfig from '../utils/user-config.js';
class AuthorizationServiceImpl {
userConfig;
constructor(userConfig) {
this.userConfig = userConfig;
}
getCurrentAuthorizationToken() {
const token = this.userConfig.read().token || process.env.CAPAWESOME_CLOUD_TOKEN || process.env.CAPAWESOME_TOKEN || null;
// Trim to remove newline characters that may be included when pasting a token,
// which would cause an invalid character error in the Authorization header.
const trimmedToken = token?.trim();
return trimmedToken || null;
}
hasAuthorizationToken() {
return !!this.getCurrentAuthorizationToken();
}
}
const authorizationService = new AuthorizationServiceImpl(userConfig);
export default authorizationService;