How to use the @expo/xdl.UserManager.getCurrentUserAsync function in @expo/xdl

To help you get started, we’ve selected a few @expo/xdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-cli / packages / expo-cli / src / printRunInstructionsAsync.ts View on Github external
export default async function printRunInstructionsAsync(): Promise {
  let user = await UserManager.getCurrentUserAsync();

  // If no user, we are offline and can't connect
  if (user) {
    log.newLine();
    log(chalk.bold('Instructions to open this project on a physical device'));
    log(`${chalk.underline('Android devices')}: scan the above QR code.`);
    log(
      `${chalk.underline('iOS devices')}: run ${chalk.bold(
        'expo send -s '
      )} in this project directory in another terminal window to send the URL to your device.`
    );

    // NOTE(brentvatne) Uncomment this when we update iOS client
    // log(
    //   `Alternatively, sign in to your account (${chalk.bold(
    //     user.username
github expo / expo-cli / packages / expo-cli / src / commands / client / index.js View on Github external
if (!_.has(exp, 'ios.config.googleMapsApiKey')) {
        const disabledReason = exp
          ? `ios.config.googleMapsApiKey does not exist in configuration file found in ${appJsonPath}`
          : 'No custom configuration file could be found. You will need to provide a json file with a valid ios.config.googleMapsApiKey field.';
        disabledServices.googleMaps = { name: 'Google Maps', reason: disabledReason };
      }
      if (_.has(exp, 'ios.googleServicesFile')) {
        const contents = await fs.readFile(
          path.resolve(projectDir, exp.ios.googleServicesFile),
          'base64'
        );
        exp.ios.googleServicesFile = contents;
      }

      const authData = await appleApi.authenticate(options);
      const user = await UserManager.getCurrentUserAsync();

      // check if any builds are in flight
      const { isAllowed, errorMessage } = await isAllowedToBuild({
        user,
        appleTeamId: authData.team.id,
      });

      if (!isAllowed) {
        throw new CommandError(
          'CLIENT_BUILD_REQUEST_NOT_ALLOWED',
          `New Expo client build request disallowed. Reason: ${errorMessage}`
        );
      }

      const bundleIdentifier = generateBundleIdentifier(authData.team.id);
      const experienceName = await getExperienceName({ user, appleTeamId: authData.team.id });
github expo / expo-cli / packages / expo-cli / src / accounts.ts View on Github external
export async function login(options: CommandOptions): Promise {
  const user = await UserManager.getCurrentUserAsync();
  const nonInteractive = options.parent && options.parent.nonInteractive;
  if (!nonInteractive) {
    if (user) {
      const question: Question = {
        type: 'confirm',
        name: 'action',
        message: `You are already logged in as ${chalk.green(user.username)}. Log in as new user?`,
      };

      const { action } = await prompt(question);
      if (!action) {
        // If user chooses to stay logged in, return
        return user;
      }
    }
    return _usernamePasswordAuth(options.username, options.password);
github expo / expo-cli / packages / expo-cli / src / commands / publish-modify.js View on Github external
.asyncActionProjectDir(async (projectDir, options) => {
      if (!options.channelId) {
        throw new Error('You must specify a channel id. You can find ids using publish:history.');
      }
      const user = await UserManager.getCurrentUserAsync();
      const api = ApiV2.clientForUser(user);
      try {
        let result = await api.postAsync('publish/rollback', {
          channelId: options.channelId,
          slug: await Project.getSlugAsync(projectDir, options),
        });
        let tableString = table.printTableJson(
          result.queryResult,
          'Channel Rollback Status ',
          'SUCCESS'
        );
        console.log(tableString);
      } catch (e) {
        log.error(e);
      }
    });
github expo / turtle / src / bin / utils / user.ts View on Github external
export async function ensureUserLoggedIn(userData: IUserData) {
  const currentUser = await UserManager.getCurrentUserAsync();
  if (currentUser) {
    return currentUser;
  } else if (!userData.username || !userData.password) {
    throw new ErrorWithProgramHelp('Please provide username and password');
  } else {
    try {
      return await UserManager.loginAsync('user-pass', userData);
    } catch (err) {
      throw new Error('Failed to log in with provided username and password');
    }
  }
}
github expo / expo-cli / packages / expo-cli / src / commands / push-creds.ts View on Github external
async function _uploadWebPushCredientials(projectDir: string, options: VapidData) {
  const isGeneration = !(options.vapidPubkey && options.vapidPvtkey);

  log('Reading project configuration...');

  const {
    args: { remotePackageName },
  } = await Exp.getPublishInfoAsync(projectDir);

  log('Logging in...');

  const user = await UserManager.getCurrentUserAsync();
  const apiClient = ApiV2.clientForUser(user);

  if (isGeneration) {
    log("Generating and setting VAPID keys on Expo's servers...");
  } else {
    log("Uploading VAPID keys to Expo's servers...");
  }

  const results = await apiClient.putAsync(`credentials/push/web/${remotePackageName}`, {
    vapidPublicKey: options.vapidPubkey,
    vapidPrivateKey: options.vapidPvtkey,
    vapidSubject: options.vapidSubject,
  });

  if (results.oldVapidData && results.oldVapidData.vapidPublicKey !== results.vapidPublicKey) {
    log(
github expo / expo-cli / packages / expo-cli / src / commands / whoami.ts View on Github external
async function action() {
  const user = await UserManager.getCurrentUserAsync({ silent: true });
  if (user) {
    log(`Logged in as ${chalk.green(user.username)}`);
    log.raw(user.username);
  } else {
    throw new CommandError('NOT_LOGGED_IN', 'Not logged in');
  }
}
github expo / expo-cli / packages / expo-cli / src / accounts.ts View on Github external
export async function loginOrRegisterIfLoggedOut(): Promise {
  let user = await UserManager.getCurrentUserAsync();
  if (user) {
    return user;
  }

  log.warn('An Expo user account is required to proceed.');

  if (program.nonInteractive) {
    throw new CommandError(
      'NOT_LOGGED_IN',
      `Not logged in. Use \`${program.name} login -u username -p password\` to log in.`
    );
  }

  const question: Question = {
    type: 'list',
    name: 'action',