From 0cd20ea2044fd6377c0ddf9484e16672c9de67bd Mon Sep 17 00:00:00 2001 From: lourw <56288712+lourw@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:20:12 -0700 Subject: [PATCH] fix(nx-cloud): update check for access token --- .../nx/src/nx-cloud/utilities/get-cloud-options.ts | 4 ++++ .../src/nx-cloud/utilities/is-workspace-claimed.ts | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/nx/src/nx-cloud/utilities/get-cloud-options.ts b/packages/nx/src/nx-cloud/utilities/get-cloud-options.ts index 3847c2a324e675..2163f2849c19f3 100644 --- a/packages/nx/src/nx-cloud/utilities/get-cloud-options.ts +++ b/packages/nx/src/nx-cloud/utilities/get-cloud-options.ts @@ -21,3 +21,7 @@ export function getCloudUrl() { export function removeTrailingSlash(apiUrl: string) { return apiUrl[apiUrl.length - 1] === '/' ? apiUrl.slice(0, -1) : apiUrl; } + +export function isNxCloudId(token: string): boolean { + return token.length === 24; +} diff --git a/packages/nx/src/nx-cloud/utilities/is-workspace-claimed.ts b/packages/nx/src/nx-cloud/utilities/is-workspace-claimed.ts index aa213fc73c3fc9..9638c1d80fb88a 100644 --- a/packages/nx/src/nx-cloud/utilities/is-workspace-claimed.ts +++ b/packages/nx/src/nx-cloud/utilities/is-workspace-claimed.ts @@ -1,15 +1,16 @@ -import { getCloudUrl } from './get-cloud-options'; +import { getCloudUrl, isNxCloudId } from './get-cloud-options'; -export async function isWorkspaceClaimed(nxCloudAccessToken) { - if (!nxCloudAccessToken) return false; +export async function isWorkspaceClaimed(accessToken: string) { + if (!accessToken) return false; const apiUrl = getCloudUrl(); try { + const requestData = isNxCloudId(accessToken) + ? { nxCloudId: accessToken } + : { nxCloudAccessToken: accessToken }; const response = await require('axios').post( `${apiUrl}/nx-cloud/is-workspace-claimed`, - { - nxCloudAccessToken, - } + requestData ); if (response.data.message) {