xref: /expo/packages/@expo/cli/src/login/index.ts (revision 51f41fa4)
1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from '../../bin/cli';
5import * as Log from '../log';
6import { assertArgs } from '../utils/args';
7import { logCmdError } from '../utils/errors';
8
9export const expoLogin: Command = async (argv) => {
10  const args = assertArgs(
11    {
12      // Types
13      '--help': Boolean,
14      '--username': String,
15      '--password': String,
16      '--otp': String,
17      // Aliases
18      '-h': '--help',
19      '-u': '--username',
20      '-p': '--password',
21    },
22    argv
23  );
24
25  if (args['--help']) {
26    Log.exit(
27      chalk`
28      {bold Description}
29        Log in to an Expo account
30
31      {bold Usage}
32        $ npx expo login
33
34      Options
35      -u, --username <string>  Username
36      -p, --password <string>  Password
37      --otp <string>           One-time password from your 2FA device
38      -h, --help               Output usage information
39    `,
40      0
41    );
42  }
43
44  const { showLoginPromptAsync } = await import('../api/user/actions');
45  return showLoginPromptAsync({
46    // Parsed options
47    username: args['--username'],
48    password: args['--password'],
49    otp: args['--otp'],
50  }).catch(logCmdError);
51};
52