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

[ENG-12793][eas-cli] make eas login and eas whoami behave more clearly when one is authenticated using EXPO_TOKEN #2461

Merged
Merged
Show file tree
Hide file tree
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
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
Loading