Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[expo-cli][xdl] Reduce warning messages when logged out. [closes:#1024] #2053

Merged
merged 1 commit into from
Apr 30, 2020
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
15 changes: 9 additions & 6 deletions packages/expo-cli/src/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ type CommandOptions = {
};
};

export async function loginOrRegisterIfLoggedOut(): Promise<User> {
let user = await UserManager.getCurrentUserAsync();
if (user) {
return user;
}

export async function loginOrRegisterAsync(): Promise<User> {
log.warn('An Expo user account is required to proceed.');

if (program.nonInteractive) {
Expand Down Expand Up @@ -62,6 +57,14 @@ export async function loginOrRegisterIfLoggedOut(): Promise<User> {
}
}

export async function loginOrRegisterIfLoggedOutAsync(): Promise<User> {
let user = await UserManager.getCurrentUserAsync();
if (user) {
return user;
}
return await loginOrRegisterAsync();
}

export async function login(options: CommandOptions): Promise<User> {
const user = await UserManager.getCurrentUserAsync();
const nonInteractive = options.parent && options.parent.nonInteractive;
Expand Down
4 changes: 2 additions & 2 deletions packages/expo-cli/src/commands/eject/LegacyEject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import semver from 'semver';
import temporary from 'tempy';

import * as PackageManager from '@expo/package-manager';
import { loginOrRegisterIfLoggedOut } from '../../accounts';
import { loginOrRegisterIfLoggedOutAsync } from '../../accounts';
import log from '../../log';
import prompt, { Question } from '../../prompt';
import { validateGitStatusAsync } from '../utils/ProjectUtils';
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function ejectAsync(projectRoot: string, options: EjectAsyncOptions
log.nested(` ${packageManager === 'npm' ? 'npm run ios' : 'yarn ios'}`);
await warnIfDependenciesRequireAdditionalSetupAsync(projectRoot);
} else if (ejectMethod === 'expokit') {
await loginOrRegisterIfLoggedOut();
await loginOrRegisterIfLoggedOutAsync();
await Detach.detachAsync(projectRoot, options);
log(chalk.green('Ejected successfully!'));
} else if (ejectMethod === 'cancel') {
Expand Down
24 changes: 12 additions & 12 deletions packages/expo-cli/src/commands/start/TerminalUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import trimStart from 'lodash/trimStart';
import openBrowser from 'react-dev-utils/openBrowser';
import readline from 'readline';
import wordwrap from 'wordwrap';
import { loginOrRegisterIfLoggedOut } from '../../accounts';
import { loginOrRegisterIfLoggedOutAsync } from '../../accounts';
import log from '../../log';
import urlOpts from '../../urlOpts';
import { startProjectInEditorAsync } from '../utils/EditorUtils';
Expand Down Expand Up @@ -57,17 +57,17 @@ const printUsage = async (projectDir: string, options: Pick<StartOptions, 'webOn
\u203A Press ${platformInfo}.
\u203A Press ${b`c`} to show info on ${u`c`}onnecting new devices.
\u203A Press ${b`d`} to open DevTools in the default web browser.
\u203A Press ${b`shift-d`} to ${openDevToolsAtStartup
? 'disable'
: 'enable'} automatically opening ${u`D`}evTools at startup.${options.webOnly
? ''
: `\n \u203A Press ${b`e`} to send an app link with ${u`e`}mail.`}
\u203A Press ${b`shift-d`} to ${
openDevToolsAtStartup ? 'disable' : 'enable'
} automatically opening ${u`D`}evTools at startup.${
options.webOnly ? '' : `\n \u203A Press ${b`e`} to send an app link with ${u`e`}mail.`
}
\u203A Press ${b`p`} to toggle ${u`p`}roduction mode. (current mode: ${i(devMode)})
\u203A Press ${b`r`} to ${u`r`}estart bundler, or ${b`shift-r`} to restart and clear cache.
\u203A Press ${b`o`} to ${u`o`}pen the project in your editor.
\u203A Press ${b`s`} to ${u`s`}ign ${username
? `out. (Signed in as ${i('@' + username)}.)`
: 'in.'}
\u203A Press ${b`s`} to ${u`s`}ign ${
username ? `out. (Signed in as ${i('@' + username)}.)` : 'in.'
}
`);
};

Expand Down Expand Up @@ -132,7 +132,7 @@ export const startAsync = async (projectDir: string, options: StartOptions) => {
UserManager.setInteractiveAuthenticationCallback(async () => {
stopWaitingForCommand();
try {
return await loginOrRegisterIfLoggedOut();
return await loginOrRegisterIfLoggedOutAsync();
} finally {
startWaitingForCommand();
}
Expand Down Expand Up @@ -272,7 +272,7 @@ export const startAsync = async (projectDir: string, options: StartOptions) => {
}
case 'D': {
clearConsole();
const enabled = !await UserSettings.getAsync('openDevToolsAtStartup', true);
const enabled = !(await UserSettings.getAsync('openDevToolsAtStartup', true));
await UserSettings.setAsync('openDevToolsAtStartup', enabled);
log(
`Automatically opening DevTools ${b(
Expand Down Expand Up @@ -316,7 +316,7 @@ Please reload the project in the Expo app for the change to take effect.`
} else {
stopWaitingForCommand();
try {
await loginOrRegisterIfLoggedOut();
await loginOrRegisterIfLoggedOutAsync();
} catch (e) {
log.error(e);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions packages/expo-cli/src/exp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '@expo/xdl';
import * as ConfigUtils from '@expo/config';

import { loginOrRegisterIfLoggedOut } from './accounts';
import { loginOrRegisterAsync } from './accounts';
import log from './log';
import update from './update';
import urlOpts from './urlOpts';
Expand Down Expand Up @@ -327,7 +327,7 @@ function runAsync(programName: string) {
Analytics.setVersionName(packageJSON.version);
_registerLogs();

UserManager.setInteractiveAuthenticationCallback(loginOrRegisterIfLoggedOut);
UserManager.setInteractiveAuthenticationCallback(loginOrRegisterAsync);

if (process.env.SERVER_URL) {
let serverUrl = process.env.SERVER_URL;
Expand Down
2 changes: 1 addition & 1 deletion packages/xdl/src/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class UserManagerInstance {
throw new XDLError('NETWORK_REQUIRED', "Can't verify user without network access");
}

let user = await this.getCurrentUserAsync();
let user = await this.getCurrentUserAsync({ silent: true });
if (!user && this._interactiveAuthenticationCallbackAsync) {
user = await this._interactiveAuthenticationCallbackAsync();
}
Expand Down