diff --git a/next.config.js b/next.config.js index b83e370e04..35cf1811fc 100644 --- a/next.config.js +++ b/next.config.js @@ -107,4 +107,9 @@ module.exports = withPlugins([ }, }], [css], + { + publicRuntimeConfig: { + domainName: process.env.DOMAIN_NAME, + }, + }, ], nextConfig); diff --git a/src/__test__/utils/getAccountId.test.js b/src/__test__/utils/getAccountId.test.js deleted file mode 100644 index 770475a963..0000000000 --- a/src/__test__/utils/getAccountId.test.js +++ /dev/null @@ -1,15 +0,0 @@ -import getAccountId from 'utils/getAccountId'; - -describe('getAccountId', () => { - it('Works in dev env', () => { - expect(getAccountId('development')).toEqual('000000000000'); - }); - - it('Works in staging env', () => { - expect(getAccountId('staging')).toEqual('242905224710'); - }); - - it('Works in prod env', () => { - expect(getAccountId('production')).toEqual('242905224710'); - }); -}); diff --git a/src/components/data-management/SamplesTable.jsx b/src/components/data-management/SamplesTable.jsx index 43aaef777a..2abf47990e 100644 --- a/src/components/data-management/SamplesTable.jsx +++ b/src/components/data-management/SamplesTable.jsx @@ -31,9 +31,7 @@ import { arrayMoveImmutable } from 'utils/array-move'; import { metadataNameToKey, metadataKeyToName, temporaryMetadataKey } from 'utils/data-management/metadataUtils'; import integrationTestConstants from 'utils/integrationTestConstants'; - import 'utils/css/data-management.css'; - import { ClipLoader } from 'react-spinners'; import useConditionalEffect from 'utils/customHooks/useConditionalEffect'; import { METADATA_DEFAULT_VALUE } from 'redux/reducers/experiments/initialState'; diff --git a/src/utils/amplify-config.js b/src/utils/amplify-config.js index 125bc0dc3f..2eeac21484 100644 --- a/src/utils/amplify-config.js +++ b/src/utils/amplify-config.js @@ -1,24 +1,6 @@ -import Environment, { ssrGetCurrentEnvironment } from './environment'; -import getAccountId from './getAccountId'; +import getAWSRegion from './getAWSRegion'; const configure = (userPoolId, identityPoolId, userPoolClientDetails) => { - const currentEnvironment = ssrGetCurrentEnvironment(); - const accountId = getAccountId(currentEnvironment); - const bucketName = `biomage-originals-${currentEnvironment}-${accountId}`; - - const storageConfig = { - Storage: { - AWSS3: { - bucket: bucketName, - region: 'eu-west-1', - dangerouslyConnectToHttpEndpointForTesting: currentEnvironment === Environment.DEVELOPMENT, - identityId: identityPoolId, - customPrefix: { - public: '', - }, - }, - }, - }; const redirectProtocol = (process.env.NODE_ENV === 'development') ? 'http:' : 'https:'; const usingProtocol = (url) => url.startsWith(redirectProtocol); const signInRedirect = userPoolClientDetails.CallbackURLs.filter(usingProtocol)[0]; @@ -26,7 +8,7 @@ const configure = (userPoolId, identityPoolId, userPoolClientDetails) => { const authConfig = { Auth: { - region: 'eu-west-1', + region: getAWSRegion(), identityPoolId, userPoolId, userPoolWebClientId: userPoolClientDetails.ClientId, @@ -45,7 +27,7 @@ const configure = (userPoolId, identityPoolId, userPoolClientDetails) => { }; return ( - { ...authConfig, ...storageConfig } + { ...authConfig } ); }; diff --git a/src/utils/apiEndpoint.js b/src/utils/apiEndpoint.js index 7147be6bd2..3baf2cc7ee 100644 --- a/src/utils/apiEndpoint.js +++ b/src/utils/apiEndpoint.js @@ -1,3 +1,5 @@ +import nextConfig from 'next/config'; + const getApiEndpoint = (location) => { try { const url = new URL(location || window.location.href); @@ -9,8 +11,8 @@ const getApiEndpoint = (location) => { if (url.hostname.includes('localhost') || url.hostname.includes('127.0.0.1')) { return 'http://localhost:3000'; } - - return 'https://api.scp.biomage.net'; + const domainName = nextConfig()?.publicRuntimeConfig?.domainName; + return `https://api.${domainName}`; } catch (error) { console.error('Failed to get API endpoint.'); console.error(error); diff --git a/src/utils/getAWSRegion.js b/src/utils/getAWSRegion.js new file mode 100644 index 0000000000..fdb75db90a --- /dev/null +++ b/src/utils/getAWSRegion.js @@ -0,0 +1,17 @@ +const getAWSRegion = () => { + // only works in ssr, where process.env is available + + if (process.env.NODE_ENV === 'development') { + return 'eu-west-1'; + } + + const { AWS_REGION, AWS_DEFAULT_REGION } = process.env; + + if (!AWS_REGION && !AWS_DEFAULT_REGION) { + throw new Error('AWS_REGION or DEFAULT_REGION must be set in the environment.'); + } + + return AWS_REGION || AWS_DEFAULT_REGION; +}; + +export default getAWSRegion; diff --git a/src/utils/getAccountId.js b/src/utils/getAccountId.js deleted file mode 100644 index a65688cc20..0000000000 --- a/src/utils/getAccountId.js +++ /dev/null @@ -1,11 +0,0 @@ -const getAccountId = (environment) => { - let accountID; - if (environment === 'development') { - accountID = '000000000000'; - } else { - accountID = '242905224710'; - } - return accountID; -}; - -export default getAccountId; diff --git a/src/utils/ssr/getAuthenticationInfo.js b/src/utils/ssr/getAuthenticationInfo.js index 2263fd4117..e081ccf42f 100644 --- a/src/utils/ssr/getAuthenticationInfo.js +++ b/src/utils/ssr/getAuthenticationInfo.js @@ -11,6 +11,7 @@ import { } from '@aws-sdk/client-cognito-identity-provider'; import { getDefaultRoleAssumerWithWebIdentity } from '@aws-sdk/client-sts'; import { fromTokenFile } from '@aws-sdk/credential-provider-web-identity'; +import getAWSRegion from 'utils/getAWSRegion'; import configure from '../amplify-config'; const getAuthenticationInfo = async () => { @@ -19,7 +20,6 @@ const getAuthenticationInfo = async () => { if (global.cachedAuthenticationInfo) { return global.cachedAuthenticationInfo; } - let additionalClientParams = {}; if (process.env.NODE_ENV !== 'development') { @@ -33,14 +33,14 @@ const getAuthenticationInfo = async () => { const identityPoolClient = new CognitoIdentityClient( { - region: 'eu-west-1', + region: getAWSRegion(), ...additionalClientParams, }, ); const userPoolClient = new CognitoIdentityProviderClient( { - region: 'eu-west-1', + region: getAWSRegion(), ...additionalClientParams, }, ); @@ -91,7 +91,7 @@ const getAuthenticationInfo = async () => { const amplifyConfig = configure( userPoolId, identityPoolId, - { ...userPoolClientDetails, Domain: `${Domain}.auth.eu-west-1.amazoncognito.com` }, + { ...userPoolClientDetails, Domain: `${Domain}.auth.${getAWSRegion()}.amazoncognito.com` }, ); const result = {