diff --git a/client/config.ts b/client/config.ts index 9c06d58..f0e1bfc 100644 --- a/client/config.ts +++ b/client/config.ts @@ -92,11 +92,21 @@ export type ConfigWithDefaults = Config & Pick >; +type ConfigInput = Omit & + Partial>; let config_: ConfigWithDefaults | undefined = undefined; -export function configure(config?: Config) { +export function configure(config?: ConfigInput) { if (config) { + const cognitoIdpEndpoint = + config.cognitoIdpEndpoint || config.userPoolId?.split("_")[0]; + if (!cognitoIdpEndpoint) { + throw new Error( + "Invalid configuration provided: either cognitoIdpEndpoint or userPoolId must be provided" + ); + } config_ = { ...config, + cognitoIdpEndpoint, crypto: config.crypto ?? Defaults.crypto, storage: config.storage ?? Defaults.storage, fetch: config.fetch ?? Defaults.fetch,