Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add opt-out for appId mismatch check during init #14013

Merged
merged 2 commits into from
Nov 13, 2024
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
23 changes: 14 additions & 9 deletions packages/amplify-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ 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}`,
});
// Opt-out mechanism for customers that are using old app backend environments with existing apps intentionally
const { AMPLIFY_SKIP_APP_ID_MISMATCH_CHECK } = process.env;
if (AMPLIFY_SKIP_APP_ID_MISMATCH_CHECK !== 'true') {
// check for appId mismatch
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}. If this is intentional, you may bypass this protection by setting the environment variable AMPLIFY_SKIP_APP_ID_MISMATCH_CHECK to true.`,
});
}
}
}

Expand Down
Loading