Skip to content

Commit

Permalink
fix: prevent init if local files belong to other app (#13954)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk authored Oct 4, 2024
1 parent 33c10fd commit d79627c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/amplify-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $TSContext, LocalEnvInfo } from '@aws-amplify/amplify-cli-core';
import { $TSContext, AmplifyError, LocalEnvInfo, stateManager } from '@aws-amplify/amplify-cli-core';
import { constructInputParams } from '../amplify-service-helper';
import { Context } from '../domain/context';
import { raisePostEnvAddEvent } from '../execution-manager';
Expand All @@ -10,6 +10,7 @@ import { initProviders } from '../init-steps/s2-initProviders';
import { scaffoldProjectHeadless } from '../init-steps/s8-scaffoldHeadless';
import { onHeadlessSuccess, onSuccess } from '../init-steps/s9-onSuccess';
import { checkForNestedProject } from './helpers/projectUtils';
import { getAmplifyAppId } from '../extensions/amplify-helpers/get-amplify-appId';

const constructExeInfo = (context: $TSContext): void => {
context.exeInfo = {
Expand All @@ -32,6 +33,18 @@ export const run = async (context: $TSContext): Promise<void> => {
constructExeInfo(context);
checkForNestedProject();

const projectPath = process.cwd();
if (stateManager.metaFileExists(projectPath)) {
const inputAppId = context.exeInfo?.inputParams?.amplify?.appId;
const appId = getAmplifyAppId();
if (inputAppId && appId && inputAppId !== appId) {
throw new AmplifyError('InvalidAmplifyAppIdError', {
message: `Amplify appId mismatch.`,
resolution: `You are currently working in the amplify project with Id ${appId}`,
});
}
}

const steps = runStrategy(!!context?.parameters?.options?.quickstart);
for (const step of steps) {
await step(context);
Expand Down

0 comments on commit d79627c

Please sign in to comment.