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

Added getUserProjectIdAsync method #3359

Merged
merged 2 commits into from
Apr 7, 2021
Merged
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
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