diff --git a/.github/workflows/opentrons-ai-client-staging-continuous-deploy.yaml b/.github/workflows/opentrons-ai-client-staging-continuous-deploy.yaml index 73d766549f7..af767b36adc 100644 --- a/.github/workflows/opentrons-ai-client-staging-continuous-deploy.yaml +++ b/.github/workflows/opentrons-ai-client-staging-continuous-deploy.yaml @@ -53,7 +53,7 @@ jobs: make setup-js - name: 'build' run: | - make -C opentrons-ai-client build + make -C opentrons-ai-client build-staging - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -61,4 +61,4 @@ jobs: aws-region: ${{ secrets.STAGING_AI_REGION }} - name: 'deploy to staging' run: | - make -C opentrons-ai-client staging-deploy \ No newline at end of file + make -C opentrons-ai-client staging-deploy diff --git a/opentrons-ai-client/Makefile b/opentrons-ai-client/Makefile index 7f10b422cf6..74be2388b78 100644 --- a/opentrons-ai-client/Makefile +++ b/opentrons-ai-client/Makefile @@ -40,6 +40,13 @@ build: vite build git rev-parse HEAD > dist/.commit + +.PHONY: build-staging +build: export NODE_ENV := staging +build: + vite build + git rev-parse HEAD > dist/.commit + # development ##################################################################### diff --git a/opentrons-ai-client/src/main.tsx b/opentrons-ai-client/src/main.tsx index 41970356433..4f0231b901d 100644 --- a/opentrons-ai-client/src/main.tsx +++ b/opentrons-ai-client/src/main.tsx @@ -6,7 +6,11 @@ import { Auth0Provider } from '@auth0/auth0-react' import { GlobalStyle } from './atoms/GlobalStyle' import { i18n } from './i18n' import { App } from './App' -import { AUTH0_DOMAIN, AUTH0_CLIENT_ID } from './resources/constants' +import { + AUTH0_DOMAIN, + PROD_AUTH0_CLIENT_ID, + STAGING_AUTH0_CLIENT_ID, +} from './resources/constants' const rootElement = document.getElementById('root') if (rootElement != null) { @@ -14,7 +18,11 @@ if (rootElement != null) { { expect(mockGetAccessTokenSilently).toHaveBeenCalledWith({ authorizationParams: { - audience: AUTH0_AUDIENCE, + audience: STAGING_AUTH0_AUDIENCE, }, }) expect(await accessToken).toBe('mockAccessToken') @@ -41,7 +41,7 @@ describe('useGetAccessToken', () => { expect(mockGetAccessTokenSilently).toHaveBeenCalledWith({ authorizationParams: { - audience: AUTH0_AUDIENCE, + audience: STAGING_AUTH0_AUDIENCE, }, }) await expect(accessToken).rejects.toThrow('mockError') diff --git a/opentrons-ai-client/src/resources/hooks/useGetAccessToken.ts b/opentrons-ai-client/src/resources/hooks/useGetAccessToken.ts index a61e05e0bb0..a010a7ecc98 100644 --- a/opentrons-ai-client/src/resources/hooks/useGetAccessToken.ts +++ b/opentrons-ai-client/src/resources/hooks/useGetAccessToken.ts @@ -1,5 +1,5 @@ import { useAuth0 } from '@auth0/auth0-react' -import { AUTH0_AUDIENCE } from '../constants' +import { PROD_AUTH0_AUDIENCE, STAGING_AUTH0_AUDIENCE } from '../constants' interface UseGetAccessTokenResult { getAccessToken: () => Promise @@ -7,12 +7,16 @@ interface UseGetAccessTokenResult { export const useGetAccessToken = (): UseGetAccessTokenResult => { const { getAccessTokenSilently } = useAuth0() + const auth0Audience = + process.env.NODE_ENV === 'production' + ? PROD_AUTH0_AUDIENCE + : STAGING_AUTH0_AUDIENCE const getAccessToken = async (): Promise => { try { const accessToken = await getAccessTokenSilently({ authorizationParams: { - audience: AUTH0_AUDIENCE, + audience: auth0Audience, }, }) return accessToken