Skip to content

Commit

Permalink
Fix running login command when there is no existing token (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sertaç Karahoda authored Jun 3, 2021
1 parent 4576d8d commit b2f6579
Showing 1 changed file with 18 additions and 14 deletions.
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."));
}
}

0 comments on commit b2f6579

Please sign in to comment.