Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt for a token when no token exists #94

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/commands-base/authenticated-command.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import Init from 'commands/init';
import { BaseCommand } from 'commands-base/base-command';
import { CONFIG_KEYS } from 'consts/config';
import { ACCESS_TOKEN_NOT_FOUND } from 'consts/messages';
import { ACCESS_TOKEN_NOT_FOUND_RUNNING_INIT } from 'consts/messages';
import { AuthenticationError } from 'errors/authentication-error';
import { ConfigService } from 'services/config-service';
import logger from 'utils/logger';

const validateAccessToken = (): void => {
const validateAccessToken = async (): Promise<void> => {
const accessToken = ConfigService.getConfigDataByKey(CONFIG_KEYS.ACCESS_TOKEN);
if (!accessToken) {
throw new AuthenticationError(ACCESS_TOKEN_NOT_FOUND);
logger.success(ACCESS_TOKEN_NOT_FOUND_RUNNING_INIT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why success here?

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const init = new Init([], { configDir: process.cwd() });
await init.run();
}
};

export abstract class AuthenticatedCommand extends BaseCommand {
public async init(): Promise<void> {
await super.init();
validateAccessToken();
await validateAccessToken();
}

protected catch(err: Error & { exitCode?: number }): any {
Expand Down
2 changes: 2 additions & 0 deletions src/consts/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const ACCESS_TOKEN_NOT_FOUND = 'Access token is missing, please run: "mapps init"';

export const ACCESS_TOKEN_NOT_FOUND_RUNNING_INIT = 'Access token is missing, running "mapps init" command';

export const APP_VERSION_ID_TO_ENTER = 'Please enter the app version id of your app:';

export const APP_ID_TO_ENTER = 'Please enter app id:';
Expand Down
Loading