Skip to content

Commit

Permalink
fix(wizard): Handle missing auth token in wizard API endpoint response (
Browse files Browse the repository at this point in the history
#566)

adjusts the SentryProjectData type to reflect that the wizard might not always receive an auth token (as we learned in INC-727). Consequently, we now handle not receiving an auth token and proceed with a dummy token and a warning for users instead
  • Loading branch information
Lms24 authored Apr 25, 2024
1 parent 4c159d9 commit 146542b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- fix(wizard): Handle missing auth token in wizard API endpoint response (#566)

## 3.22.0

- feat(nextjs): Ask users about tunnelRoute option (#556)
Expand Down
31 changes: 27 additions & 4 deletions src/utils/clack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export const SENTRY_PROPERTIES_FILE = 'sentry.properties';

const SAAS_URL = 'https://sentry.io/';

const DUMMY_AUTH_TOKEN = '_YOUR_SENTRY_AUTH_TOKEN_';

interface WizardProjectData {
apiKeys: {
token: string;
apiKeys?: {
token?: string;
};
projects: SentryProjectData[];
projects?: SentryProjectData[];
}

export interface CliSetupConfig {
Expand Down Expand Up @@ -779,16 +781,37 @@ export async function getOrAskForProjectData(
);
Sentry.setTag('no-projects-found', true);
await abort();
// This rejection won't return due to the abort call but TS doesn't know that
return Promise.reject();
}

const selectedProject = await traceStep('select-project', () =>
askForProjectSelection(projects),
);

const { token } = apiKeys ?? {};

if (!token) {
clack.log.error(`Didn't receive an auth token. This shouldn't happen :(
Please let us know if you think this is a bug in the wizard:
${chalk.cyan('https://github.com/getsentry/sentry-wizard/issues')}`);

clack.log.info(`In the meantime, we'll add a dummy auth token (${chalk.cyan(
`"${DUMMY_AUTH_TOKEN}"`,
)}) for you to replace later.
Create your auth token here:
${chalk.cyan(
selfHosted
? `${sentryUrl}organizations/${selectedProject.organization.slug}/settings/auth-tokens`
: `https://${selectedProject.organization.slug}.sentry.io/settings/auth-tokens`,
)}`);
}

return {
sentryUrl,
selfHosted,
authToken: apiKeys.token,
authToken: apiKeys?.token || DUMMY_AUTH_TOKEN,
selectedProject,
};
}
Expand Down

0 comments on commit 146542b

Please sign in to comment.