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

Commit

Permalink
Added getUserProjectIdAsync method (#3359)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Apr 7, 2021
1 parent 0b76c5d commit d4a4427
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/xdl/src/User.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExpoConfig } from '@expo/config-types';
import camelCase from 'lodash/camelCase';
import isEmpty from 'lodash/isEmpty';
import snakeCase from 'lodash/snakeCase';
Expand Down Expand Up @@ -289,6 +290,33 @@ export class UserManagerInstance {
return user;
}

/**
* Used in expo-constants to generate the `id` property statically for an app in custom managed workflow.
* This `id` is used for legacy Expo services AuthSession proxy and Expo notifications device ID.
*
* @param manifest
* @returns
*/
async getProjectCurrentFullNameAsync(manifest: ExpoConfig): Promise<string> {
const username = await this.getProjectAccountNameAsync(manifest);
return `@${username}/${manifest.slug}`;
}

async getProjectAccountNameAsync(manifest: ExpoConfig): Promise<string> {
// TODO: Must match what's generated in Expo Go.
if (manifest.owner) {
return manifest.owner;
} else if (process.env.EAS_BUILD_USERNAME) {
return process.env.EAS_BUILD_USERNAME;
} else if (!Config.offline) {
const username = await this.getCurrentUsernameAsync();
if (username) {
return username;
}
}
return ANONYMOUS_USERNAME;
}

async getCurrentUsernameAsync(): Promise<string | null> {
const token = UserSettings.accessToken();
if (token) {
Expand Down

0 comments on commit d4a4427

Please sign in to comment.