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

Fix running login command when there is no existing token #90

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Changes from all 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
32 changes: 18 additions & 14 deletions src/commands/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import logger from "../../util/logger";

import * as envUtil from "../../util/env";
import * as authFileUtil from "../../util/auth-file";
import { AuthenticationService, AUTH_METHOD } from "../../service/index";
import { AuthenticationService, AUTH_METHOD } from "../../service";

export interface LoginOptions {
noBrowser: boolean;
Expand All @@ -30,19 +30,23 @@ export async function login(options: LoginOptions): Promise<void> {
if (answer.choice !== "y") {
return;
}

const authService = new AuthenticationService({
token: existingToken,
method: AUTH_METHOD.LOCAL_AUTH_FILE
});

await authService.promptForLogin({
ignoreSaveTokenErrors: false,
noBrowser: options.noBrowser,
forceRenewal: true
});

logger.info(chalk.bold("\n🦄 Successfully authenticated."));
}

const authService = new AuthenticationService(
existingToken
? {
token: existingToken,
method: AUTH_METHOD.LOCAL_AUTH_FILE
}
: undefined
);

await authService.promptForLogin({
ignoreSaveTokenErrors: false,
noBrowser: options.noBrowser,
forceRenewal: true
});

logger.info(chalk.bold("\n🦄 Successfully authenticated."));
}
}