Skip to content

Commit b9d2423

Browse files
authored
Ask either cognitoIdpEndpoint or userPoolId (#204)
1 parent 0832b30 commit b9d2423

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

client/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,21 @@ export type ConfigWithDefaults = Config &
9292
Pick<Config, "storage" | "crypto" | "fetch" | "location" | "history">
9393
>;
9494

95+
type ConfigInput = Omit<Config, "cognitoIdpEndpoint"> &
96+
Partial<Pick<Config, "cognitoIdpEndpoint">>;
9597
let config_: ConfigWithDefaults | undefined = undefined;
96-
export function configure(config?: Config) {
98+
export function configure(config?: ConfigInput) {
9799
if (config) {
100+
const cognitoIdpEndpoint =
101+
config.cognitoIdpEndpoint || config.userPoolId?.split("_")[0];
102+
if (!cognitoIdpEndpoint) {
103+
throw new Error(
104+
"Invalid configuration provided: either cognitoIdpEndpoint or userPoolId must be provided"
105+
);
106+
}
98107
config_ = {
99108
...config,
109+
cognitoIdpEndpoint,
100110
crypto: config.crypto ?? Defaults.crypto,
101111
storage: config.storage ?? Defaults.storage,
102112
fetch: config.fetch ?? Defaults.fetch,

0 commit comments

Comments
 (0)