Skip to content

Commit

Permalink
[ENG-12793][eas-cli] make eas login and eas whoami behave more cl…
Browse files Browse the repository at this point in the history
…early when one is authenticated using `EXPO_TOKEN` (#2461)

* eas login and eas whoami improvements

* apply suggested change

* Update packages/eas-cli/src/commands/account/view.ts

Co-authored-by: Will Schurman <[email protected]>

* add changelog

* fix changelog

---------

Co-authored-by: Will Schurman <[email protected]>
  • Loading branch information
szdziedzic and wschurman authored Jul 18, 2024
1 parent 17ecdb2 commit 5745639
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ This is the log of notable changes to EAS CLI and related packages.

### 🧹 Chores

- Indicate if a user is logged in using `EXPO_TOKEN` when running `eas whoami` command. ([#2461](https://github.com/expo/eas-cli/pull/2461) by [@szdziedzic](https://github.com/szdziedzic))
- Throw error when `eas login` command is run with `EXPO_TOKEN` environment variable set. ([#2461](https://github.com/expo/eas-cli/pull/2461) by [@szdziedzic](https://github.com/szdziedzic))
- Check if user is already logged in when running `eas login` command. ([#2461](https://github.com/expo/eas-cli/pull/2461) by [@szdziedzic](https://github.com/szdziedzic))

## [10.2.0](https://github.com/expo/eas-cli/releases/tag/v10.2.0) - 2024-07-15

### 🎉 New features
Expand Down
29 changes: 27 additions & 2 deletions packages/eas-cli/src/commands/account/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Flags } from '@oclif/core';
import { Errors, Flags } from '@oclif/core';
import chalk from 'chalk';

import EasCommand from '../../commandUtils/EasCommand';
import Log from '../../log';
import { confirmAsync } from '../../prompts';
import { getActorDisplayName } from '../../user/User';

export default class AccountLogin extends EasCommand {
static override description = 'log in with your Expo account';
Expand All @@ -17,6 +20,7 @@ export default class AccountLogin extends EasCommand {
};

static override contextDefinition = {
...this.ContextOptions.MaybeLoggedIn,
...this.ContextOptions.SessionManagment,
};

Expand All @@ -25,7 +29,28 @@ export default class AccountLogin extends EasCommand {
flags: { sso },
} = await this.parse(AccountLogin);

const { sessionManager } = await this.getContextAsync(AccountLogin, { nonInteractive: false });
const {
sessionManager,
maybeLoggedIn: { actor },
} = await this.getContextAsync(AccountLogin, { nonInteractive: false });

if (sessionManager.getAccessToken()) {
throw new Error(
'EXPO_TOKEN is set in your environment, and is being used for all EAS authentication. To use username/password authentication, unset EXPO_TOKEN in your environment and re-run the command.'
);
}

if (actor) {
Log.warn(`You are already logged in as ${chalk.bold(getActorDisplayName(actor))}.`);

const shouldContinue = await confirmAsync({
message: 'Do you want to continue?',
});
if (!shouldContinue) {
Errors.error('Aborted', { exit: 1 });
}
}

await sessionManager.showLoginPromptAsync({ sso });
Log.log('Logged in');
}
Expand Down
7 changes: 6 additions & 1 deletion packages/eas-cli/src/commands/account/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ export default class AccountView extends EasCommand {

static override contextDefinition = {
...this.ContextOptions.MaybeLoggedIn,
...this.ContextOptions.SessionManagment,
};

async runAsync(): Promise<void> {
const {
maybeLoggedIn: { actor },
sessionManager,
} = await this.getContextAsync(AccountView, { nonInteractive: true });
if (actor) {
Log.log(chalk.green(getActorDisplayName(actor)));
const loggedInAs = sessionManager.getAccessToken()
? `${getActorDisplayName(actor)} (authenticated using EXPO_TOKEN)`
: getActorDisplayName(actor);
Log.log(chalk.green(loggedInAs));

// personal account is included, only show if more accounts that personal account
// but do show personal account in list if there are more
Expand Down

0 comments on commit 5745639

Please sign in to comment.