Skip to content

Commit

Permalink
Ask either cognitoIdpEndpoint or userPoolId (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottokruse authored Sep 27, 2024
1 parent 0832b30 commit b9d2423
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@ export type ConfigWithDefaults = Config &
Pick<Config, "storage" | "crypto" | "fetch" | "location" | "history">
>;

type ConfigInput = Omit<Config, "cognitoIdpEndpoint"> &
Partial<Pick<Config, "cognitoIdpEndpoint">>;
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,
Expand Down

0 comments on commit b9d2423

Please sign in to comment.