Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/core/config/ConfigurationProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe('ConfigurationProvider', () => {
);
});

it('points to the installer when a required value is missing', () => {
expect(() => provider.getValue('clientId')).toThrow(
/WORKOS_CLIENT_ID\)\. .*npx workos@latest install/,
);
});

it('converts boolean values from strings', () => {
const source = vi.fn().mockReturnValue('false');
provider.configure(source);
Expand Down Expand Up @@ -191,6 +197,10 @@ describe('ConfigurationProvider', () => {
);
});

it('points agents to the installer, which needs no WorkOS account', () => {
expect(() => provider.validate()).toThrow(/npx workos@latest install/);
});

it('shows current length of invalid cookiePassword', () => {
provider.configure({
clientId: 'test-client',
Expand Down
9 changes: 7 additions & 2 deletions src/core/config/ConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const defaultSource: ValueSource = (key: string): string | undefined => {
}
};

/** Coding agents read this from the error, so the fix needs no human or account. */
const MISSING_CONFIG_HINT =
'To set up AuthKit without a WorkOS account, run `npx workos@latest install`: it creates an environment you can claim later and writes these variables.';

/**
* Configuration class for AuthKit.
* This class is used to manage configuration values and provide defaults.
Expand Down Expand Up @@ -92,7 +96,7 @@ export class ConfigurationProvider {

if (this.requiredKeys.includes(key)) {
throw new Error(
`Missing required configuration value for ${key} (${envKey}).`,
`Missing required configuration value for ${key} (${envKey}). ${MISSING_CONFIG_HINT}`,
);
}

Expand Down Expand Up @@ -179,7 +183,8 @@ export class ConfigurationProvider {
'AuthKit configuration error. Missing or invalid environment variables:\n\n' +
errors.map(e => ` • ${e}`).join('\n') +
'\n\nSet these environment variables or call configure() with the required values.' +
'\nGet your values from the WorkOS Dashboard: https://dashboard.workos.com',
'\nGet your values from the WorkOS Dashboard: https://dashboard.workos.com' +
'\nNo WorkOS account yet? Run `npx workos@latest install`: it creates an environment you can claim later and writes these variables.',
);
}
}
Expand Down
Loading