From 7972d82edbe2ab1d6a2d5adcbac9bd3252435690 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 6 Dec 2024 10:32:54 +0530 Subject: [PATCH 01/46] Add init commit for new branch --- lib/ts/recipe/webauthn/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/ts/recipe/webauthn/index.ts diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts new file mode 100644 index 00000000..afbe2de8 --- /dev/null +++ b/lib/ts/recipe/webauthn/index.ts @@ -0,0 +1,16 @@ +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +// TODO: Define the code From 46bfcf62ed4cbc1c8b1ae1274c11f4dcd1b76b28 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 09:13:48 +0530 Subject: [PATCH 02/46] Add init types definition for webauthn recipe --- lib/ts/recipe/webauthn/recipe.ts | 14 ++++ lib/ts/recipe/webauthn/types.ts | 115 +++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 lib/ts/recipe/webauthn/recipe.ts create mode 100644 lib/ts/recipe/webauthn/types.ts diff --git a/lib/ts/recipe/webauthn/recipe.ts b/lib/ts/recipe/webauthn/recipe.ts new file mode 100644 index 00000000..a1d80543 --- /dev/null +++ b/lib/ts/recipe/webauthn/recipe.ts @@ -0,0 +1,14 @@ +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts new file mode 100644 index 00000000..fbf1ef9a --- /dev/null +++ b/lib/ts/recipe/webauthn/types.ts @@ -0,0 +1,115 @@ +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +import { + NormalisedInputType as AuthRecipeNormalisedInputType, + InputType as AuthRecipeInputType, +} from "../authRecipe/types"; +import { + RecipePostAPIHookContext, + RecipePreAPIHookContext, + UserInput as RecipeModuleUserInput, + RecipeFunctionOptions, +} from "../recipeModule/types"; +import OverrideableBuilder from "supertokens-js-override"; + +export type PreAndPostAPIHookAction = + | "REGISTER_OPTIONS" + | "SIGN_IN_OPTIONS" + | "SIGN_UP" + | "SIGN_IN" + | "EMAIL_EXISTS" + | "GENERATE_RECOVER_ACCOUNT_TOKEN" + | "RECOVER_ACCOUNT"; + +export type PreAPIHookContext = RecipePreAPIHookContext; +export type PostAPIHookContext = RecipePostAPIHookContext; + +export type ResidentKey = "required" | "preferred" | "discouraged"; +export type UserVerification = "required" | "preferred" | "discouraged"; + +export type UserInput = { + override?: { + functions?: ( + originalImplementation: RecipeInterface, + builder: OverrideableBuilder + ) => RecipeInterface; + }; +} & RecipeModuleUserInput; + +export type InputType = AuthRecipeInputType & UserInput; + +export type NormalisedInputType = AuthRecipeNormalisedInputType & { + override: { + functions: ( + originalImplementation: RecipeInterface, + builder: OverrideableBuilder + ) => RecipeInterface; + }; +}; + +export type RecipeInterface = { + registerOptions: ( + input: { options?: RecipeFunctionOptions; userContext: any } & ( + | { email: string } + | { recoverAccountToken: string } + ) + ) => Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + >; +}; From 1cccad9cd0cf6fda2b8d8d56d1ca6ee48b8bd782 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 10:52:56 +0530 Subject: [PATCH 03/46] Add more type definitions for recipe --- lib/ts/recipe/webauthn/types.ts | 75 +++++++++++++++++++++++++++++++++ lib/ts/types.ts | 6 +++ 2 files changed, 81 insertions(+) diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index fbf1ef9a..5bf9145d 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -13,6 +13,7 @@ * under the License. */ +import { GeneralErrorResponse, User } from "../../types"; import { NormalisedInputType as AuthRecipeNormalisedInputType, InputType as AuthRecipeInputType, @@ -60,6 +61,20 @@ export type NormalisedInputType = AuthRecipeNormalisedInputType; + type: "public-key"; +}; + export type RecipeInterface = { registerOptions: ( input: { options?: RecipeFunctionOptions; userContext: any } & ( @@ -112,4 +127,64 @@ export type RecipeInterface = { fetchResponse: Response; } >; + signInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + signUp: (input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + >; + signIn: (input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; + emailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >; }; diff --git a/lib/ts/types.ts b/lib/ts/types.ts index decad7d7..ea146183 100644 --- a/lib/ts/types.ts +++ b/lib/ts/types.ts @@ -171,3 +171,9 @@ export type User = { }; }[]; }; + +export declare type GeneralErrorResponse = { + status: "GENERAL_ERROR"; + message: string; + fetchResponse: Response; +}; From 06d8b348b0d33cfa85e7925035970e2ed7f06ae9 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 10:56:43 +0530 Subject: [PATCH 04/46] Add some more type definitions for recover account and generate token --- lib/ts/recipe/webauthn/types.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 5bf9145d..8d358cf1 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -187,4 +187,34 @@ export type RecipeInterface = { } | GeneralErrorResponse >; + generateRecoverAccountToken: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + } + | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } + | GeneralErrorResponse + >; + recoverAccount: (input: { + token: string; + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + email: string; + } + | GeneralErrorResponse + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + >; }; From 831ebb9768a3a7610bedbbc296a7e1f4bda20df6 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 11:28:29 +0530 Subject: [PATCH 05/46] Add definition for registerOptions in recipe implementation --- lib/ts/recipe/webauthn/recipe.ts | 4 + .../recipe/webauthn/recipeImplementation.ts | 109 ++++++++++++++++++ lib/ts/recipe/webauthn/utils.ts | 28 +++++ 3 files changed, 141 insertions(+) create mode 100644 lib/ts/recipe/webauthn/recipeImplementation.ts create mode 100644 lib/ts/recipe/webauthn/utils.ts diff --git a/lib/ts/recipe/webauthn/recipe.ts b/lib/ts/recipe/webauthn/recipe.ts index a1d80543..6bb08b59 100644 --- a/lib/ts/recipe/webauthn/recipe.ts +++ b/lib/ts/recipe/webauthn/recipe.ts @@ -12,3 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ + +import AuthRecipe from "../authRecipe"; +import { PreAndPostAPIHookAction } from "../multitenancy"; +import { NormalisedInputType, RecipeInterface, InputType } from "./types"; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts new file mode 100644 index 00000000..a1b52ab4 --- /dev/null +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -0,0 +1,109 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +import Querier from "../../querier"; +import { RecipeInterface, ResidentKey, UserVerification } from "./types"; +import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModule/types"; +import { PreAndPostAPIHookAction } from "./types"; + +export default function getRecipeImplementation( + recipeImplInput: RecipeImplementationInput +): RecipeInterface { + const querier = new Querier(recipeImplInput.recipeId, recipeImplInput.appInfo); + + return { + registerOptions: async function ({ + options, + userContext, + email, + recoverAccountToken, + }: { options?: RecipeFunctionOptions; userContext: any } & ( + | { email: string; recoverAccountToken?: never } + | { recoverAccountToken: string; email?: never } + )) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + >( + undefined, + "/webauthn/options/register", + { + body: JSON.stringify({ + email, + recoverAccountToken, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "REGISTER_OPTIONS", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "REGISTER_OPTIONS", + userContext: userContext, + }) + ); + + return { + ...jsonBody, + fetchResponse, + }; + }, + }; +} diff --git a/lib/ts/recipe/webauthn/utils.ts b/lib/ts/recipe/webauthn/utils.ts new file mode 100644 index 00000000..a296bf0c --- /dev/null +++ b/lib/ts/recipe/webauthn/utils.ts @@ -0,0 +1,28 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +import { normaliseAuthRecipe } from "../authRecipe/utils"; +import { InputType, NormalisedInputType, RecipeInterface } from "./types"; + +export function normaliseUserInput(config: InputType): NormalisedInputType { + const override: any = { + functions: (originalImplementation: RecipeInterface) => originalImplementation, + ...config.override, + }; + + return { + ...normaliseAuthRecipe(config), + override, + }; +} From e6f5a65fe19fe6c0f2836da1136dd369ee71991b Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 11:36:45 +0530 Subject: [PATCH 06/46] Add definition for signInOptions for recipe implementation --- .../recipe/webauthn/recipeImplementation.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index a1b52ab4..3e7dc98c 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -17,6 +17,7 @@ import Querier from "../../querier"; import { RecipeInterface, ResidentKey, UserVerification } from "./types"; import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModule/types"; import { PreAndPostAPIHookAction } from "./types"; +import { GeneralErrorResponse } from "../../types"; export default function getRecipeImplementation( recipeImplInput: RecipeImplementationInput @@ -100,6 +101,47 @@ export default function getRecipeImplementation( }) ); + return { + ...jsonBody, + fetchResponse, + }; + }, + signInOptions: async function ({ email, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + >( + undefined, + "/webauthn/options/signin", + { + body: JSON.stringify({ + email, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_IN_OPTIONS", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_IN_OPTIONS", + userContext: userContext, + }) + ); + return { ...jsonBody, fetchResponse, From d3b22135537a3bf5852976233800a840e089aed1 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 13:29:46 +0530 Subject: [PATCH 07/46] Add recipe implementation for signup and signin methods --- .../recipe/webauthn/recipeImplementation.ts | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 3e7dc98c..3479d54a 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -17,7 +17,7 @@ import Querier from "../../querier"; import { RecipeInterface, ResidentKey, UserVerification } from "./types"; import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModule/types"; import { PreAndPostAPIHookAction } from "./types"; -import { GeneralErrorResponse } from "../../types"; +import { GeneralErrorResponse, User } from "../../types"; export default function getRecipeImplementation( recipeImplInput: RecipeImplementationInput @@ -142,6 +142,88 @@ export default function getRecipeImplementation( }) ); + return { + ...jsonBody, + fetchResponse, + }; + }, + signUp: async function ({ webauthnGeneratedOptionsId, credential, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + >( + undefined, + "/webauthn/signup", + { + body: JSON.stringify({ + webauthnGeneratedOptionsId, + credential, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_UP", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_UP", + userContext: userContext, + }) + ); + + return { + ...jsonBody, + fetchResponse, + }; + }, + signIn: async function ({ webauthnGeneratedOptionsId, credential, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + user: User; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >( + undefined, + "/webauthn/signin", + { + body: JSON.stringify({ + webauthnGeneratedOptionsId, + credential, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_IN", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_IN", + userContext: userContext, + }) + ); + return { ...jsonBody, fetchResponse, From cfcd682bc54249e270f95fdc458dff49ef8f82b2 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 13:59:21 +0530 Subject: [PATCH 08/46] Add recipe implementation for the email exists webauthn functionailty --- .../recipe/webauthn/recipeImplementation.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 3479d54a..f555ceb8 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -224,6 +224,36 @@ export default function getRecipeImplementation( }) ); + return { + ...jsonBody, + fetchResponse, + }; + }, + emailExists: async function ({ email, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.get< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >( + undefined, + "/webauthn/email/exists", + {}, + { email: email }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "EMAIL_EXISTS", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "EMAIL_EXISTS", + userContext: userContext, + }) + ); + return { ...jsonBody, fetchResponse, From 555f536c74a89dc52232c2ecb0d2e52bf6a9137d Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 15:19:34 +0530 Subject: [PATCH 09/46] Add remaining recipe implementations for webauthn --- .../recipe/webauthn/recipeImplementation.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index f555ceb8..65b4a915 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -254,6 +254,80 @@ export default function getRecipeImplementation( }) ); + return { + ...jsonBody, + fetchResponse, + }; + }, + generateRecoverAccountToken: async function ({ email, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + } + | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } + | GeneralErrorResponse + >( + undefined, + "/user/webauthn/reset/token", + { + body: JSON.stringify({ + email, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "GENERATE_RECOVER_ACCOUNT_TOKEN", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "GENERATE_RECOVER_ACCOUNT_TOKEN", + userContext: userContext, + }) + ); + + return { + ...jsonBody, + fetchResponse, + }; + }, + recoverAccount: async function ({ token, webauthnGeneratedOptionsId, credential, options, userContext }) { + const { jsonBody, fetchResponse } = await querier.post< + | { + status: "OK"; + user: User; + email: string; + } + | GeneralErrorResponse + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + >( + undefined, + "/user/webauthn/reset", + { + body: JSON.stringify({ + token, + webauthnGeneratedOptionsId, + credential, + }), + }, + Querier.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "RECOVER_ACCOUNT", + options: options, + userContext: userContext, + }), + Querier.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "RECOVER_ACCOUNT", + userContext: userContext, + }) + ); + return { ...jsonBody, fetchResponse, From 16a06805b633e15b4995aa2734315f60bc5f4992 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 15:26:52 +0530 Subject: [PATCH 10/46] Add recipe definition for webauthn --- lib/ts/recipe/webauthn/recipe.ts | 64 ++++++++++++++++++- .../recipe/webauthn/recipeImplementation.ts | 2 + 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lib/ts/recipe/webauthn/recipe.ts b/lib/ts/recipe/webauthn/recipe.ts index 6bb08b59..7a4546ad 100644 --- a/lib/ts/recipe/webauthn/recipe.ts +++ b/lib/ts/recipe/webauthn/recipe.ts @@ -14,5 +14,65 @@ */ import AuthRecipe from "../authRecipe"; -import { PreAndPostAPIHookAction } from "../multitenancy"; -import { NormalisedInputType, RecipeInterface, InputType } from "./types"; +import { NormalisedInputType, RecipeInterface, InputType, UserInput, PreAndPostAPIHookAction } from "./types"; +import { normaliseUserInput } from "./utils"; +import OverrideableBuilder from "supertokens-js-override"; +import RecipeImplementation from "./recipeImplementation"; +import { CreateRecipeFunction, NormalisedAppInfo } from "../../types"; +import { checkForSSRErrorAndAppendIfNeeded, isTest } from "../../utils"; + +export default class Recipe extends AuthRecipe { + static instance?: Recipe; + static RECIPE_ID = "webauthn"; + + recipeImplementation: RecipeInterface; + + constructor(config: InputType) { + super(normaliseUserInput(config)); + + const builder = new OverrideableBuilder( + RecipeImplementation({ + recipeId: this.config.recipeId, + appInfo: this.config.appInfo, + clientType: this.config.clientType, + preAPIHook: this.config.preAPIHook, + postAPIHook: this.config.postAPIHook, + }) + ); + this.recipeImplementation = builder.override(this.config.override.functions).build(); + } + + static init(config?: UserInput): CreateRecipeFunction { + return (appInfo: NormalisedAppInfo, clientType: string | undefined) => { + Recipe.instance = new Recipe({ + ...config, + recipeId: Recipe.RECIPE_ID, + appInfo, + clientType, + }); + + return Recipe.instance; + }; + } + + static getInstanceOrThrow(): Recipe { + if (Recipe.instance === undefined) { + let error = "No instance of Webauthn found. Make sure to call the Webauthn.init method."; + error = checkForSSRErrorAndAppendIfNeeded(error); + + throw Error(error); + } + + return Recipe.instance; + } + + static reset(): void { + if (!isTest()) { + return; + } + Recipe.instance = undefined; + return; + } +} + +export { Recipe }; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 65b4a915..8c923d24 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -335,3 +335,5 @@ export default function getRecipeImplementation( }, }; } + +export { getRecipeImplementation }; From 7fd7d1ca0d7daaff132a912d26ebfbbd1579bab5 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 15:38:44 +0530 Subject: [PATCH 11/46] Add exposable method for registerOptions functionality in webauthn --- lib/ts/recipe/webauthn/index.ts | 87 ++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index afbe2de8..b13f3d8e 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -13,4 +13,89 @@ * under the License. */ -// TODO: Define the code +import { getNormalisedUserContext } from "../../utils"; +import { RecipeFunctionOptions } from "../emailpassword"; +import Recipe from "./recipe"; +import { ResidentKey, UserInput, UserVerification } from "./types"; + +export default class RecipeWrapper { + static init(config?: UserInput) { + return Recipe.init(config); + } + + /** + * Registers a new device based on the passed options and returns the + * challenge to be fulfilled in order for successful addition of the identity. + * + * @param email (OPTIONAL) Email to register the options against. This cannot be passed along with recoverAccountToken. + * + * @param recoverAccountToken (OPTIONAL) Recover account token in case this is being generated in that context. This cannot be passed along with email. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the created device (secret, etc.) + */ + static registerOptions( + input: { options?: RecipeFunctionOptions; userContext: any } & ( + | { email: string } + | { recoverAccountToken: string } + ) + ): Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.registerOptions({ + ...input, + userContext: getNormalisedUserContext(input?.userContext), + }); + } +} + +const init = RecipeWrapper.init; +const registerOptions = RecipeWrapper.registerOptions; + +export { init, registerOptions }; From f78b025cda558ff212d024cf27a1521a76b6a72b Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 16:08:47 +0530 Subject: [PATCH 12/46] Add wrapper definitions for sign in with options and signup --- lib/ts/recipe/webauthn/index.ts | 80 +++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index b13f3d8e..f3407aca 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -13,10 +13,11 @@ * under the License. */ +import { GeneralErrorResponse, User } from "../../types"; import { getNormalisedUserContext } from "../../utils"; -import { RecipeFunctionOptions } from "../emailpassword"; +import { RecipeFunctionOptions } from "../recipeModule/types"; import Recipe from "./recipe"; -import { ResidentKey, UserInput, UserVerification } from "./types"; +import { CredentialPayload, ResidentKey, UserInput, UserVerification } from "./types"; export default class RecipeWrapper { static init(config?: UserInput) { @@ -35,7 +36,7 @@ export default class RecipeWrapper { * * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) * - * @returns `{ status: "OK", ...}` if successful along a description of the created device (secret, etc.) + * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) */ static registerOptions( input: { options?: RecipeFunctionOptions; userContext: any } & ( @@ -93,6 +94,79 @@ export default class RecipeWrapper { userContext: getNormalisedUserContext(input?.userContext), }); } + + /** + * TODO: Add description once Victor shares the difference between registerOptions and this. + * + * @param email Email to add signin options against. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) + */ + static signinOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + > { + return Recipe.getInstanceOrThrow().recipeImplementation.signInOptions({ + ...input, + userContext: getNormalisedUserContext(input?.userContext), + }); + } + + /** + * Signup to ST with the webauthn options ID and the credential received from the + * device. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + static signUp(input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.signUp({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; From c48299824bdf5e5d01850690dbf53d4075181b33 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 17:51:52 +0530 Subject: [PATCH 13/46] Update function definition of signinOptions --- lib/ts/recipe/webauthn/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index f3407aca..7e4fe522 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -96,7 +96,8 @@ export default class RecipeWrapper { } /** - * TODO: Add description once Victor shares the difference between registerOptions and this. + * Returns details about how the authenticator to should verify that a signin + * is correct. * * @param email Email to add signin options against. * From 849febd167e107942e2f81621cb31a2664071423 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 17:53:56 +0530 Subject: [PATCH 14/46] Export signInOptions and signUp method from webauthn --- lib/ts/recipe/webauthn/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 7e4fe522..efb51873 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -107,7 +107,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - static signinOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static signInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -172,5 +172,7 @@ export default class RecipeWrapper { const init = RecipeWrapper.init; const registerOptions = RecipeWrapper.registerOptions; +const signInOptions = RecipeWrapper.signInOptions; +const signUp = RecipeWrapper.signUp; -export { init, registerOptions }; +export { init, registerOptions, signInOptions, signUp }; From 2e393731bd7c82734742120230baa5cd4281af13 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 17:56:03 +0530 Subject: [PATCH 15/46] Add support for passing tenantId properly in recipe implementation --- .../recipe/webauthn/recipeImplementation.ts | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 8c923d24..54b6d2d2 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -18,6 +18,7 @@ import { RecipeInterface, ResidentKey, UserVerification } from "./types"; import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModule/types"; import { PreAndPostAPIHookAction } from "./types"; import { GeneralErrorResponse, User } from "../../types"; +import Multitenancy from "../multitenancy/recipe"; export default function getRecipeImplementation( recipeImplInput: RecipeImplementationInput @@ -80,7 +81,9 @@ export default function getRecipeImplementation( fetchResponse: Response; } >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/webauthn/options/register", { body: JSON.stringify({ @@ -122,7 +125,9 @@ export default function getRecipeImplementation( } | GeneralErrorResponse >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/webauthn/options/signin", { body: JSON.stringify({ @@ -164,7 +169,9 @@ export default function getRecipeImplementation( | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } | { status: "EMAIL_ALREADY_EXISTS_ERROR" } >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/webauthn/signup", { body: JSON.stringify({ @@ -203,7 +210,9 @@ export default function getRecipeImplementation( } | GeneralErrorResponse >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/webauthn/signin", { body: JSON.stringify({ @@ -237,7 +246,9 @@ export default function getRecipeImplementation( } | GeneralErrorResponse >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/webauthn/email/exists", {}, { email: email }, @@ -267,7 +278,9 @@ export default function getRecipeImplementation( | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } | GeneralErrorResponse >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/user/webauthn/reset/token", { body: JSON.stringify({ @@ -306,7 +319,9 @@ export default function getRecipeImplementation( | { status: "INVALID_GENERATED_OPTIONS_ERROR" } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } >( - undefined, + await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), "/user/webauthn/reset", { body: JSON.stringify({ From 6acc5d4d498bc9bf8b8caa05b557c29131d31dd5 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 18:05:26 +0530 Subject: [PATCH 16/46] Add signIn method wrapper for webauthn --- lib/ts/recipe/webauthn/index.ts | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index efb51873..fadc4ad0 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -168,11 +168,48 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Sign in with the credential and the generated options ID. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + static signIn(input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + > { + return Recipe.getInstanceOrThrow().recipeImplementation.signIn({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; const registerOptions = RecipeWrapper.registerOptions; const signInOptions = RecipeWrapper.signInOptions; const signUp = RecipeWrapper.signUp; +const signIn = RecipeWrapper.signIn; -export { init, registerOptions, signInOptions, signUp }; +export { init, registerOptions, signInOptions, signUp, signIn }; From b531229bc217185b2e569164b1e6a415c9c175cc Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 18:10:12 +0530 Subject: [PATCH 17/46] Add emailExists method for webauthn recipe --- lib/ts/recipe/webauthn/index.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index fadc4ad0..cb98bbf9 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -204,6 +204,30 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Checks whether there is an webauthn user with the passed email. + * + * @param email Email to check for existence + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence + */ + static emailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + > { + return Recipe.getInstanceOrThrow().recipeImplementation.emailExists({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -211,5 +235,6 @@ const registerOptions = RecipeWrapper.registerOptions; const signInOptions = RecipeWrapper.signInOptions; const signUp = RecipeWrapper.signUp; const signIn = RecipeWrapper.signIn; +const emailExists = RecipeWrapper.emailExists; -export { init, registerOptions, signInOptions, signUp, signIn }; +export { init, registerOptions, signInOptions, signUp, signIn, emailExists }; From 25cf6dce65839473f2c249b223dbc1f29e5bbbb5 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 18:24:38 +0530 Subject: [PATCH 18/46] Add generateRecoverAccount method for webauthn recipe --- lib/ts/recipe/webauthn/index.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index cb98bbf9..cf9338b1 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -228,6 +228,34 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Generate and send a recover account token. + * + * @param email Email to send the recover account token to. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful + */ + static generateRecoverAccountToken(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + } + | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } + | GeneralErrorResponse + > { + return Recipe.getInstanceOrThrow().recipeImplementation.generateRecoverAccountToken({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -236,5 +264,6 @@ const signInOptions = RecipeWrapper.signInOptions; const signUp = RecipeWrapper.signUp; const signIn = RecipeWrapper.signIn; const emailExists = RecipeWrapper.emailExists; +const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; -export { init, registerOptions, signInOptions, signUp, signIn, emailExists }; +export { init, registerOptions, signInOptions, signUp, signIn, emailExists, generateRecoverAccountToken }; From 24aa20613dd8ff475bbf58b6f1ea7349bccfdf14 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 18:28:50 +0530 Subject: [PATCH 19/46] Add recover account method from webauthn recipe --- lib/ts/recipe/webauthn/index.ts | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index cf9338b1..9643144d 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -256,6 +256,46 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Recover the account using the token received in email. + * + * @param token Recovery token received in email + * + * @param webauthnGeneratedOptionsId Stored options ID for webauthn + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static recoverAccount(input: { + token: string; + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + email: string; + } + | GeneralErrorResponse + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.recoverAccount({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -265,5 +305,15 @@ const signUp = RecipeWrapper.signUp; const signIn = RecipeWrapper.signIn; const emailExists = RecipeWrapper.emailExists; const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; +const recoverAccount = RecipeWrapper.recoverAccount; -export { init, registerOptions, signInOptions, signUp, signIn, emailExists, generateRecoverAccountToken }; +export { + init, + registerOptions, + signInOptions, + signUp, + signIn, + emailExists, + generateRecoverAccountToken, + recoverAccount, +}; From 99cd8920425b7d2245352281adc8cf4f5c558c82 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 10 Dec 2024 07:53:37 +0530 Subject: [PATCH 20/46] Update changelog and run build with version bump --- CHANGELOG.md | 4 + ... => emailpassword.29adfb46da80ec0ed95a.js} | 2 +- ...emailverification.6732ffa5dbfbe9eacad6.js} | 2 +- ...> multifactorauth.b8f3ad6ba2bd6b853403.js} | 2 +- ...s => multitenancy.7207668f6f89bd4e9374.js} | 2 +- ...=> oauth2provider.ec55653f929453c7c92d.js} | 2 +- ...s => passwordless.999853645df047881fba.js} | 2 +- ...js => supertokens.cc12824dc1ea4eaffacf.js} | 2 +- ....js => thirdparty.03d01cdb65fa98811780.js} | 2 +- ...60a92b.js => totp.5f7125f744605fbe7cbc.js} | 2 +- lib/build/recipe/webauthn/index.d.ts | 291 ++++++++++ lib/build/recipe/webauthn/index.js | 208 +++++++ lib/build/recipe/webauthn/recipe.d.ts | 13 + lib/build/recipe/webauthn/recipe.js | 105 ++++ .../recipe/webauthn/recipeImplementation.d.ts | 7 + .../recipe/webauthn/recipeImplementation.js | 507 ++++++++++++++++++ lib/build/recipe/webauthn/types.d.ts | 231 ++++++++ lib/build/recipe/webauthn/types.js | 16 + lib/build/recipe/webauthn/utils.d.ts | 2 + lib/build/recipe/webauthn/utils.js | 44 ++ lib/build/types.d.ts | 5 + lib/build/version.d.ts | 2 +- lib/build/version.js | 2 +- lib/ts/version.ts | 2 +- package-lock.json | 2 +- package.json | 2 +- 26 files changed, 1447 insertions(+), 14 deletions(-) rename bundle/{emailpassword.ae01b8ec196ce465b388.js => emailpassword.29adfb46da80ec0ed95a.js} (99%) rename bundle/{emailverification.82f788ef8c6e54629d91.js => emailverification.6732ffa5dbfbe9eacad6.js} (99%) rename bundle/{multifactorauth.7bd389e3e1b318dd9465.js => multifactorauth.b8f3ad6ba2bd6b853403.js} (99%) rename bundle/{multitenancy.87953764c9541dcabac0.js => multitenancy.7207668f6f89bd4e9374.js} (99%) rename bundle/{oauth2provider.5c7cbd31b88824ed69d5.js => oauth2provider.ec55653f929453c7c92d.js} (99%) rename bundle/{passwordless.91a6d329c0c6732c5be8.js => passwordless.999853645df047881fba.js} (99%) rename bundle/{supertokens.c4d6fbc63b01b92c703a.js => supertokens.cc12824dc1ea4eaffacf.js} (99%) rename bundle/{thirdparty.9db47093453d7509e101.js => thirdparty.03d01cdb65fa98811780.js} (99%) rename bundle/{totp.5c03596a78559860a92b.js => totp.5f7125f744605fbe7cbc.js} (99%) create mode 100644 lib/build/recipe/webauthn/index.d.ts create mode 100644 lib/build/recipe/webauthn/index.js create mode 100644 lib/build/recipe/webauthn/recipe.d.ts create mode 100644 lib/build/recipe/webauthn/recipe.js create mode 100644 lib/build/recipe/webauthn/recipeImplementation.d.ts create mode 100644 lib/build/recipe/webauthn/recipeImplementation.js create mode 100644 lib/build/recipe/webauthn/types.d.ts create mode 100644 lib/build/recipe/webauthn/types.js create mode 100644 lib/build/recipe/webauthn/utils.d.ts create mode 100644 lib/build/recipe/webauthn/utils.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 077d81e2..4e7c9133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [0.15.0] - 2024-12-10 + +- Added webauthn support for various functionalities + ## [0.14.0] - 2024-10-07 - Added the OAuth2Provider recipe diff --git a/bundle/emailpassword.ae01b8ec196ce465b388.js b/bundle/emailpassword.29adfb46da80ec0ed95a.js similarity index 99% rename from bundle/emailpassword.ae01b8ec196ce465b388.js rename to bundle/emailpassword.29adfb46da80ec0ed95a.js index 88c9aed4..6c71fa20 100644 --- a/bundle/emailpassword.ae01b8ec196ce465b388.js +++ b/bundle/emailpassword.29adfb46da80ec0ed95a.js @@ -1 +1 @@ -"use strict";var supertokensEmailPassword;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[581],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},6022:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6022,e(e.s=6022));supertokensEmailPassword=t}]); \ No newline at end of file +"use strict";var supertokensEmailPassword;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[581],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},6022:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6022,e(e.s=6022));supertokensEmailPassword=t}]); \ No newline at end of file diff --git a/bundle/emailverification.82f788ef8c6e54629d91.js b/bundle/emailverification.6732ffa5dbfbe9eacad6.js similarity index 99% rename from bundle/emailverification.82f788ef8c6e54629d91.js rename to bundle/emailverification.6732ffa5dbfbe9eacad6.js index 1ff9c746..af50df14 100644 --- a/bundle/emailverification.82f788ef8c6e54629d91.js +++ b/bundle/emailverification.6732ffa5dbfbe9eacad6.js @@ -1 +1 @@ -"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var a=n.getValueFromPayload(r,o);if(void 0===a)return!0;var s=i.now(),l=n.getLastFetchedTime(r,o);return void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file +"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var a=n.getValueFromPayload(r,o);if(void 0===a)return!0;var s=i.now(),l=n.getLastFetchedTime(r,o);return void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file diff --git a/bundle/multifactorauth.7bd389e3e1b318dd9465.js b/bundle/multifactorauth.b8f3ad6ba2bd6b853403.js similarity index 99% rename from bundle/multifactorauth.7bd389e3e1b318dd9465.js rename to bundle/multifactorauth.b8f3ad6ba2bd6b853403.js index dd1c5322..62167bc4 100644 --- a/bundle/multifactorauth.7bd389e3e1b318dd9465.js +++ b/bundle/multifactorauth.b8f3ad6ba2bd6b853403.js @@ -1 +1 @@ -"use strict";var supertokensMultiFactorAuth;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[910],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},8140:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MultiFactorAuthClaimClass=t.MultiFactorAuthClaim=t.resyncSessionAndFetchMFAInfo=t.init=void 0;var r=n(6970);Object.defineProperty(t,"MultiFactorAuthClaimClass",{enumerable:!0,get:function(){return r.MultiFactorAuthClaimClass}});var o=n(7504),i=n(8122),a=function(){function e(){}return e.init=function(e){return o.default.init(e)},e.resyncSessionAndFetchMFAInfo=function(e){var t;return o.default.getInstanceOrThrow().recipeImplementation.resyncSessionAndFetchMFAInfo({options:null!==(t=null==e?void 0:e.options)&&void 0!==t?t:{},userContext:(0,i.getNormalisedUserContext)(null==e?void 0:e.userContext)})},e.MultiFactorAuthClaim=o.default.MultiFactorAuthClaim,e}();t.default=a;var s=a.init;t.init=s;var u=a.resyncSessionAndFetchMFAInfo;t.resyncSessionAndFetchMFAInfo=u;var c=a.MultiFactorAuthClaim;t.MultiFactorAuthClaim=c},6970:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(8140,e(e.s=8140));supertokensMultiFactorAuth=t}]); \ No newline at end of file +"use strict";var supertokensMultiFactorAuth;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[910],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},8140:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MultiFactorAuthClaimClass=t.MultiFactorAuthClaim=t.resyncSessionAndFetchMFAInfo=t.init=void 0;var r=n(6970);Object.defineProperty(t,"MultiFactorAuthClaimClass",{enumerable:!0,get:function(){return r.MultiFactorAuthClaimClass}});var o=n(7504),i=n(8122),a=function(){function e(){}return e.init=function(e){return o.default.init(e)},e.resyncSessionAndFetchMFAInfo=function(e){var t;return o.default.getInstanceOrThrow().recipeImplementation.resyncSessionAndFetchMFAInfo({options:null!==(t=null==e?void 0:e.options)&&void 0!==t?t:{},userContext:(0,i.getNormalisedUserContext)(null==e?void 0:e.userContext)})},e.MultiFactorAuthClaim=o.default.MultiFactorAuthClaim,e}();t.default=a;var s=a.init;t.init=s;var u=a.resyncSessionAndFetchMFAInfo;t.resyncSessionAndFetchMFAInfo=u;var c=a.MultiFactorAuthClaim;t.MultiFactorAuthClaim=c},6970:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(8140,e(e.s=8140));supertokensMultiFactorAuth=t}]); \ No newline at end of file diff --git a/bundle/multitenancy.87953764c9541dcabac0.js b/bundle/multitenancy.7207668f6f89bd4e9374.js similarity index 99% rename from bundle/multitenancy.87953764c9541dcabac0.js rename to bundle/multitenancy.7207668f6f89bd4e9374.js index a359faf0..6bc1affd 100644 --- a/bundle/multitenancy.87953764c9541dcabac0.js +++ b/bundle/multitenancy.7207668f6f89bd4e9374.js @@ -1 +1 @@ -"use strict";var supertokensMultitenancy;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[746,560],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},4694:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(2797,e(e.s=2797));supertokensMultitenancy=t}]); \ No newline at end of file +"use strict";var supertokensMultitenancy;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[746,560],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},4694:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(2797,e(e.s=2797));supertokensMultitenancy=t}]); \ No newline at end of file diff --git a/bundle/oauth2provider.5c7cbd31b88824ed69d5.js b/bundle/oauth2provider.ec55653f929453c7c92d.js similarity index 99% rename from bundle/oauth2provider.5c7cbd31b88824ed69d5.js rename to bundle/oauth2provider.ec55653f929453c7c92d.js index cf1631a2..94873ceb 100644 --- a/bundle/oauth2provider.5c7cbd31b88824ed69d5.js +++ b/bundle/oauth2provider.ec55653f929453c7c92d.js @@ -1 +1 @@ -"use strict";var supertokensOAuth2Provider;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[678],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(8021,e(e.s=8021));supertokensOAuth2Provider=t}]); \ No newline at end of file +"use strict";var supertokensOAuth2Provider;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[678],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(8021,e(e.s=8021));supertokensOAuth2Provider=t}]); \ No newline at end of file diff --git a/bundle/passwordless.91a6d329c0c6732c5be8.js b/bundle/passwordless.999853645df047881fba.js similarity index 99% rename from bundle/passwordless.91a6d329c0c6732c5be8.js rename to bundle/passwordless.999853645df047881fba.js index 7892437b..25be6e6a 100644 --- a/bundle/passwordless.91a6d329c0c6732c5be8.js +++ b/bundle/passwordless.999853645df047881fba.js @@ -1 +1 @@ -"use strict";var supertokensPasswordless;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[87],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw d;return void 0===u?[3,4]:(f=d.clone(),[4,u({requestInit:c,url:e,fetchResponse:f})]);case 3:i.sent(),i.label=4;case 4:return[2,d]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY=void 0,t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY="supertokens-passwordless-loginAttemptInfo"},6525:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6525,e(e.s=6525));supertokensPasswordless=t}]); \ No newline at end of file +"use strict";var supertokensPasswordless;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[87],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw d;return void 0===u?[3,4]:(f=d.clone(),[4,u({requestInit:c,url:e,fetchResponse:f})]);case 3:i.sent(),i.label=4;case 4:return[2,d]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY=void 0,t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY="supertokens-passwordless-loginAttemptInfo"},6525:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6525,e(e.s=6525));supertokensPasswordless=t}]); \ No newline at end of file diff --git a/bundle/supertokens.c4d6fbc63b01b92c703a.js b/bundle/supertokens.cc12824dc1ea4eaffacf.js similarity index 99% rename from bundle/supertokens.c4d6fbc63b01b92c703a.js rename to bundle/supertokens.cc12824dc1ea4eaffacf.js index a8ba9136..00dec7dd 100644 --- a/bundle/supertokens.c4d6fbc63b01b92c703a.js +++ b/bundle/supertokens.cc12824dc1ea4eaffacf.js @@ -1 +1 @@ -"use strict";var supertokens;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[842],{280:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(569),t)},7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},4587:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CookieHandlerReference=void 0;var r=n(2118);Object.defineProperty(t,"CookieHandlerReference",{enumerable:!0,get:function(){return r.CookieHandlerReference}})},7335:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DateProviderReference=void 0;var r=n(9236);Object.defineProperty(t,"DateProviderReference",{enumerable:!0,get:function(){return r.DateProviderReference}})},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},569:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.init=void 0;var r=n(3146),o=function(){function e(){}return e.init=function(e){r.default.init(e)},e}();t.default=o,t.init=o.init},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});var r=n(8122),o=n(4587),i=n(7528),a=n(5941),s=n(6984),u=n(7335),c=function(){function e(e){var t=this;if(this.recipeList=[],this.appInfo=(0,r.normaliseInputAppInfoOrThrowError)(e.appInfo),void 0===e.recipeList||0===e.recipeList.length)throw new Error("Please provide at least one recipe to the supertokens.init function call. See https://supertokens.io/docs/emailpassword/quick-setup/frontend");var n=!1;void 0!==e.enableDebugLogs&&(n=e.enableDebugLogs);var o=!1;this.recipeList=e.recipeList.map((function(r){var i=r(t.appInfo,e.clientType,n);return i.config.recipeId===s.Recipe.RECIPE_ID&&(o=!0),i})),o||this.recipeList.push(s.Recipe.init()(this.appInfo,e.clientType,n))}return e.init=function(t){o.CookieHandlerReference.init(t.cookieHandler),i.WindowHandlerReference.init(t.windowHandler),u.DateProviderReference.init(t.dateProvider),void 0===e.instance?(e.instance=new e(t),a.PostSuperTokensInitCallbacks.runPostInitCallbacks()):console.warn("SuperTokens was already initialized")},e.getInstanceOrThrow=function(){if(void 0===e.instance){var t="SuperTokens must be initialized before calling this method.";throw t=(0,r.checkForSSRErrorAndAppendIfNeeded)(t),new Error(t)}return e.instance},e.reset=function(){(0,r.isTest)()?(s.Recipe.reset(),e.instance=void 0):console.warn("Calling reset() is only supported during testing")},e}();t.default=c},8122:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},2118:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(5209))},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(280,e(e.s=280));supertokens=t}]); \ No newline at end of file +"use strict";var supertokens;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[842],{280:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(569),t)},7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},4587:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CookieHandlerReference=void 0;var r=n(2118);Object.defineProperty(t,"CookieHandlerReference",{enumerable:!0,get:function(){return r.CookieHandlerReference}})},7335:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DateProviderReference=void 0;var r=n(9236);Object.defineProperty(t,"DateProviderReference",{enumerable:!0,get:function(){return r.DateProviderReference}})},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},569:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.init=void 0;var r=n(3146),o=function(){function e(){}return e.init=function(e){r.default.init(e)},e}();t.default=o,t.init=o.init},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});var r=n(8122),o=n(4587),i=n(7528),a=n(5941),s=n(6984),u=n(7335),c=function(){function e(e){var t=this;if(this.recipeList=[],this.appInfo=(0,r.normaliseInputAppInfoOrThrowError)(e.appInfo),void 0===e.recipeList||0===e.recipeList.length)throw new Error("Please provide at least one recipe to the supertokens.init function call. See https://supertokens.io/docs/emailpassword/quick-setup/frontend");var n=!1;void 0!==e.enableDebugLogs&&(n=e.enableDebugLogs);var o=!1;this.recipeList=e.recipeList.map((function(r){var i=r(t.appInfo,e.clientType,n);return i.config.recipeId===s.Recipe.RECIPE_ID&&(o=!0),i})),o||this.recipeList.push(s.Recipe.init()(this.appInfo,e.clientType,n))}return e.init=function(t){o.CookieHandlerReference.init(t.cookieHandler),i.WindowHandlerReference.init(t.windowHandler),u.DateProviderReference.init(t.dateProvider),void 0===e.instance?(e.instance=new e(t),a.PostSuperTokensInitCallbacks.runPostInitCallbacks()):console.warn("SuperTokens was already initialized")},e.getInstanceOrThrow=function(){if(void 0===e.instance){var t="SuperTokens must be initialized before calling this method.";throw t=(0,r.checkForSSRErrorAndAppendIfNeeded)(t),new Error(t)}return e.instance},e.reset=function(){(0,r.isTest)()?(s.Recipe.reset(),e.instance=void 0):console.warn("Calling reset() is only supported during testing")},e}();t.default=c},8122:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},2118:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(5209))},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(280,e(e.s=280));supertokens=t}]); \ No newline at end of file diff --git a/bundle/thirdparty.9db47093453d7509e101.js b/bundle/thirdparty.03d01cdb65fa98811780.js similarity index 99% rename from bundle/thirdparty.9db47093453d7509e101.js rename to bundle/thirdparty.03d01cdb65fa98811780.js index 4ee890f9..58c92c9a 100644 --- a/bundle/thirdparty.9db47093453d7509e101.js +++ b/bundle/thirdparty.03d01cdb65fa98811780.js @@ -1 +1 @@ -"use strict";var supertokensThirdParty;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[298],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=r(942);t.default=n.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function r(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var n=new URL(e);return t?n.hostname.startsWith("localhost")||(o=n.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+n.host:"https://"+n.host:n.protocol+"//"+n.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),r(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=r(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function r(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return r(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),r("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var n=this;this.startsWith=function(e){return n.value.startsWith(e.value)},this.appendPath=function(t){return new e(n.value+t.value)},this.getAsStringDangerous=function(){return n.value},this.value=r(t)}},634:function(e,t,r){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(r,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,n){var o=r.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(r.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===n?s:s+"?"+new URLSearchParams(n)},this.getResponseJsonOrThrowGeneralError=function(e){return o(r,void 0,void 0,(function(){var t,r;return i(this,(function(n){switch(n.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=n.sent()).status)throw r=void 0===t.message?"No Error Message Provided":t.message,new u.default(r);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var r=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,r(n(n({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var r=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,r(n(n({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,r){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var n=r(6069);t.normaliseAuthRecipe=function(e){return(0,n.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,r){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},n=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]>parseInt(e)/4).toString(16)}))};return void 0!==e&&void 0!==e.frontendRedirectURI&&(t.frontendRedirectURI=e.frontendRedirectURI),btoa(JSON.stringify(t))},verifyAndGetStateOrThrowError:function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){if(void 0===e.stateObjectFromStorage||void 0===e.stateObjectFromStorage.stateForAuthProvider)throw new Error("No valid auth state present in session storage");if(void 0===e.stateFromAuthProvider)throw new Error("No state recieved from auth provider");if(e.stateObjectFromStorage.expiresAt{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var n=r(7528),o=r(7611),i=r(7992),a=r(1260),s=r(5811);function u(e,t){if("loginMethods"in t)return t;var r=void 0!==t.email?[t.email]:[],n=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:r,phoneNumbers:n,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var r=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];r.searchParams.set(t,n)})),r.href}catch(r){var n=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(n).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];o.searchParams.set(t,r)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,r,n=new a.default("");return void 0!==e.apiGatewayPath&&(n=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:n.appendPath((t=o.DEFAULT_API_BASE_PATH,r=e.apiBasePath,void 0!==r?new a.default(r):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,r=e.userContext;return(0,s.getGlobalClaimValidators)(t,r)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var n=r(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return n.WindowHandlerReference}})},4328:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var n=r(2652),o=r(788),i=r(2582);t.getGlobalClaimValidators=function(e,t){var r=(0,n.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:r});return void 0!==e?e(s,r):s}},942:(e,t,r)=>{function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}t.__esModule=!0;let o=r(6398);void 0!==o.default?n(o):n({default:o,...o})},5811:(e,t,r)=>{t.__esModule=!0,function(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}(r(4328))},9092:(e,t,r)=>{t.__esModule=!0,function(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}(r(7860))}},e=>{var t=(1257,e(e.s=1257));supertokensThirdParty=t}]); \ No newline at end of file +"use strict";var supertokensThirdParty;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[298],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=r(942);t.default=n.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function r(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var n=new URL(e);return t?n.hostname.startsWith("localhost")||(o=n.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+n.host:"https://"+n.host:n.protocol+"//"+n.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),r(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=r(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function r(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return r(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),r("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var n=this;this.startsWith=function(e){return n.value.startsWith(e.value)},this.appendPath=function(t){return new e(n.value+t.value)},this.getAsStringDangerous=function(){return n.value},this.value=r(t)}},634:function(e,t,r){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:d})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(r,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,n){var o=r.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(r.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===n?s:s+"?"+new URLSearchParams(n)},this.getResponseJsonOrThrowGeneralError=function(e){return o(r,void 0,void 0,(function(){var t,r;return i(this,(function(n){switch(n.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=n.sent()).status)throw r=void 0===t.message?"No Error Message Provided":t.message,new u.default(r);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var r=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,r(n(n({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var r=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,r(n(n({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,r){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var n=r(6069);t.normaliseAuthRecipe=function(e){return(0,n.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,r){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},n=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]>parseInt(e)/4).toString(16)}))};return void 0!==e&&void 0!==e.frontendRedirectURI&&(t.frontendRedirectURI=e.frontendRedirectURI),btoa(JSON.stringify(t))},verifyAndGetStateOrThrowError:function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){if(void 0===e.stateObjectFromStorage||void 0===e.stateObjectFromStorage.stateForAuthProvider)throw new Error("No valid auth state present in session storage");if(void 0===e.stateFromAuthProvider)throw new Error("No state recieved from auth provider");if(e.stateObjectFromStorage.expiresAt{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var n=r(7528),o=r(7611),i=r(7992),a=r(1260),s=r(5811);function u(e,t){if("loginMethods"in t)return t;var r=void 0!==t.email?[t.email]:[],n=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:r,phoneNumbers:n,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var r=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];r.searchParams.set(t,n)})),r.href}catch(r){var n=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(n).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];o.searchParams.set(t,r)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,r,n=new a.default("");return void 0!==e.apiGatewayPath&&(n=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:n.appendPath((t=o.DEFAULT_API_BASE_PATH,r=e.apiBasePath,void 0!==r?new a.default(r):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return n.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,r=e.userContext;return(0,s.getGlobalClaimValidators)(t,r)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var n=r(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return n.WindowHandlerReference}})},4328:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var n=r(2652),o=r(788),i=r(2582);t.getGlobalClaimValidators=function(e,t){var r=(0,n.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:r});return void 0!==e?e(s,r):s}},942:(e,t,r)=>{function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}t.__esModule=!0;let o=r(6398);void 0!==o.default?n(o):n({default:o,...o})},5811:(e,t,r)=>{t.__esModule=!0,function(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}(r(4328))},9092:(e,t,r)=>{t.__esModule=!0,function(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}(r(7860))}},e=>{var t=(1257,e(e.s=1257));supertokensThirdParty=t}]); \ No newline at end of file diff --git a/bundle/totp.5c03596a78559860a92b.js b/bundle/totp.5f7125f744605fbe7cbc.js similarity index 99% rename from bundle/totp.5c03596a78559860a92b.js rename to bundle/totp.5f7125f744605fbe7cbc.js index 526b6101..e155a633 100644 --- a/bundle/totp.5c03596a78559860a92b.js +++ b/bundle/totp.5f7125f744605fbe7cbc.js @@ -1 +1 @@ -"use strict";var supertokensTOTP;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[728],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},1996:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.14.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(5194,e(e.s=5194));supertokensTOTP=t}]); \ No newline at end of file +"use strict";var supertokensTOTP;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[728],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,a=e.action,s=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},a=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},1996:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),a=n(1260),s=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new a.default("");return void 0!==e.apiGatewayPath&&(r=new a.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new a.default(n):new a.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,s.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.15.0",t.supported_fdi=["3.1","4.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(5194,e(e.s=5194));supertokensTOTP=t}]); \ No newline at end of file diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts new file mode 100644 index 00000000..5b03ce99 --- /dev/null +++ b/lib/build/recipe/webauthn/index.d.ts @@ -0,0 +1,291 @@ +import { GeneralErrorResponse, User } from "../../types"; +import { RecipeFunctionOptions } from "../recipeModule/types"; +import { CredentialPayload, ResidentKey, UserInput, UserVerification } from "./types"; +export default class RecipeWrapper { + static init( + config?: UserInput + ): import("../../types").CreateRecipeFunction; + /** + * Registers a new device based on the passed options and returns the + * challenge to be fulfilled in order for successful addition of the identity. + * + * @param email (OPTIONAL) Email to register the options against. This cannot be passed along with recoverAccountToken. + * + * @param recoverAccountToken (OPTIONAL) Recover account token in case this is being generated in that context. This cannot be passed along with email. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) + */ + static registerOptions( + input: { + options?: RecipeFunctionOptions; + userContext: any; + } & ( + | { + email: string; + } + | { + recoverAccountToken: string; + } + ) + ): Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + >; + /** + * Returns details about how the authenticator to should verify that a signin + * is correct. + * + * @param email Email to add signin options against. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) + */ + static signInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + /** + * Signup to ST with the webauthn options ID and the credential received from the + * device. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + static signUp(input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + } + | { + status: "EMAIL_ALREADY_EXISTS_ERROR"; + } + >; + /** + * Sign in with the credential and the generated options ID. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + static signIn(input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; + /** + * Checks whether there is an webauthn user with the passed email. + * + * @param email Email to check for existence + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence + */ + static emailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >; + /** + * Generate and send a recover account token. + * + * @param email Email to send the recover account token to. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful + */ + static generateRecoverAccountToken(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + } + | { + status: "RECOVER_ACCOUNT_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; + /** + * Recover the account using the token received in email. + * + * @param token Recovery token received in email + * + * @param webauthnGeneratedOptionsId Stored options ID for webauthn + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static recoverAccount(input: { + token: string; + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + email: string; + } + | GeneralErrorResponse + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + } + >; +} +declare const init: typeof RecipeWrapper.init; +declare const registerOptions: typeof RecipeWrapper.registerOptions; +declare const signInOptions: typeof RecipeWrapper.signInOptions; +declare const signUp: typeof RecipeWrapper.signUp; +declare const signIn: typeof RecipeWrapper.signIn; +declare const emailExists: typeof RecipeWrapper.emailExists; +declare const generateRecoverAccountToken: typeof RecipeWrapper.generateRecoverAccountToken; +declare const recoverAccount: typeof RecipeWrapper.recoverAccount; +export { + init, + registerOptions, + signInOptions, + signUp, + signIn, + emailExists, + generateRecoverAccountToken, + recoverAccount, +}; diff --git a/lib/build/recipe/webauthn/index.js b/lib/build/recipe/webauthn/index.js new file mode 100644 index 00000000..cb5040eb --- /dev/null +++ b/lib/build/recipe/webauthn/index.js @@ -0,0 +1,208 @@ +"use strict"; +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +var __assign = + (this && this.__assign) || + function () { + __assign = + Object.assign || + function (t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.recoverAccount = + exports.generateRecoverAccountToken = + exports.emailExists = + exports.signIn = + exports.signUp = + exports.signInOptions = + exports.registerOptions = + exports.init = + void 0; +var utils_1 = require("../../utils"); +var recipe_1 = require("./recipe"); +var RecipeWrapper = /** @class */ (function () { + function RecipeWrapper() {} + RecipeWrapper.init = function (config) { + return recipe_1.default.init(config); + }; + /** + * Registers a new device based on the passed options and returns the + * challenge to be fulfilled in order for successful addition of the identity. + * + * @param email (OPTIONAL) Email to register the options against. This cannot be passed along with recoverAccountToken. + * + * @param recoverAccountToken (OPTIONAL) Recover account token in case this is being generated in that context. This cannot be passed along with email. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) + */ + RecipeWrapper.registerOptions = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerOptions( + __assign(__assign({}, input), { + userContext: (0, utils_1.getNormalisedUserContext)( + input === null || input === void 0 ? void 0 : input.userContext + ), + }) + ); + }; + /** + * Returns details about how the authenticator to should verify that a signin + * is correct. + * + * @param email Email to add signin options against. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) + */ + RecipeWrapper.signInOptions = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.signInOptions( + __assign(__assign({}, input), { + userContext: (0, utils_1.getNormalisedUserContext)( + input === null || input === void 0 ? void 0 : input.userContext + ), + }) + ); + }; + /** + * Signup to ST with the webauthn options ID and the credential received from the + * device. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + RecipeWrapper.signUp = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.signUp( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Sign in with the credential and the generated options ID. + * + * @param webauthnGeneratedOptionsId ID of the stored options + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) + */ + RecipeWrapper.signIn = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.signIn( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Checks whether there is an webauthn user with the passed email. + * + * @param email Email to check for existence + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence + */ + RecipeWrapper.emailExists = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.emailExists( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Generate and send a recover account token. + * + * @param email Email to send the recover account token to. + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful + */ + RecipeWrapper.generateRecoverAccountToken = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.generateRecoverAccountToken( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Recover the account using the token received in email. + * + * @param token Recovery token received in email + * + * @param webauthnGeneratedOptionsId Stored options ID for webauthn + * + * @param credential Details of the credential + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + RecipeWrapper.recoverAccount = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.recoverAccount( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + return RecipeWrapper; +})(); +exports.default = RecipeWrapper; +var init = RecipeWrapper.init; +exports.init = init; +var registerOptions = RecipeWrapper.registerOptions; +exports.registerOptions = registerOptions; +var signInOptions = RecipeWrapper.signInOptions; +exports.signInOptions = signInOptions; +var signUp = RecipeWrapper.signUp; +exports.signUp = signUp; +var signIn = RecipeWrapper.signIn; +exports.signIn = signIn; +var emailExists = RecipeWrapper.emailExists; +exports.emailExists = emailExists; +var generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; +exports.generateRecoverAccountToken = generateRecoverAccountToken; +var recoverAccount = RecipeWrapper.recoverAccount; +exports.recoverAccount = recoverAccount; diff --git a/lib/build/recipe/webauthn/recipe.d.ts b/lib/build/recipe/webauthn/recipe.d.ts new file mode 100644 index 00000000..30eccfba --- /dev/null +++ b/lib/build/recipe/webauthn/recipe.d.ts @@ -0,0 +1,13 @@ +import AuthRecipe from "../authRecipe"; +import { NormalisedInputType, RecipeInterface, InputType, UserInput, PreAndPostAPIHookAction } from "./types"; +import { CreateRecipeFunction } from "../../types"; +export default class Recipe extends AuthRecipe { + static instance?: Recipe; + static RECIPE_ID: string; + recipeImplementation: RecipeInterface; + constructor(config: InputType); + static init(config?: UserInput): CreateRecipeFunction; + static getInstanceOrThrow(): Recipe; + static reset(): void; +} +export { Recipe }; diff --git a/lib/build/recipe/webauthn/recipe.js b/lib/build/recipe/webauthn/recipe.js new file mode 100644 index 00000000..8cebe41c --- /dev/null +++ b/lib/build/recipe/webauthn/recipe.js @@ -0,0 +1,105 @@ +"use strict"; +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +var __extends = + (this && this.__extends) || + (function () { + var extendStatics = function (d, b) { + extendStatics = + Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && + function (d, b) { + d.__proto__ = b; + }) || + function (d, b) { + for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; + }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { + this.constructor = d; + } + d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __()); + }; + })(); +var __assign = + (this && this.__assign) || + function () { + __assign = + Object.assign || + function (t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Recipe = void 0; +var authRecipe_1 = require("../authRecipe"); +var utils_1 = require("./utils"); +var supertokens_js_override_1 = require("supertokens-js-override"); +var recipeImplementation_1 = require("./recipeImplementation"); +var utils_2 = require("../../utils"); +var Recipe = /** @class */ (function (_super) { + __extends(Recipe, _super); + function Recipe(config) { + var _this = _super.call(this, (0, utils_1.normaliseUserInput)(config)) || this; + var builder = new supertokens_js_override_1.default( + (0, recipeImplementation_1.default)({ + recipeId: _this.config.recipeId, + appInfo: _this.config.appInfo, + clientType: _this.config.clientType, + preAPIHook: _this.config.preAPIHook, + postAPIHook: _this.config.postAPIHook, + }) + ); + _this.recipeImplementation = builder.override(_this.config.override.functions).build(); + return _this; + } + Recipe.init = function (config) { + return function (appInfo, clientType) { + Recipe.instance = new Recipe( + __assign(__assign({}, config), { recipeId: Recipe.RECIPE_ID, appInfo: appInfo, clientType: clientType }) + ); + return Recipe.instance; + }; + }; + Recipe.getInstanceOrThrow = function () { + if (Recipe.instance === undefined) { + var error = "No instance of Webauthn found. Make sure to call the Webauthn.init method."; + error = (0, utils_2.checkForSSRErrorAndAppendIfNeeded)(error); + throw Error(error); + } + return Recipe.instance; + }; + Recipe.reset = function () { + if (!(0, utils_2.isTest)()) { + return; + } + Recipe.instance = undefined; + return; + }; + Recipe.RECIPE_ID = "webauthn"; + return Recipe; +})(authRecipe_1.default); +exports.Recipe = Recipe; +exports.default = Recipe; diff --git a/lib/build/recipe/webauthn/recipeImplementation.d.ts b/lib/build/recipe/webauthn/recipeImplementation.d.ts new file mode 100644 index 00000000..b95eb006 --- /dev/null +++ b/lib/build/recipe/webauthn/recipeImplementation.d.ts @@ -0,0 +1,7 @@ +import { RecipeInterface } from "./types"; +import { RecipeImplementationInput } from "../recipeModule/types"; +import { PreAndPostAPIHookAction } from "./types"; +export default function getRecipeImplementation( + recipeImplInput: RecipeImplementationInput +): RecipeInterface; +export { getRecipeImplementation }; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js new file mode 100644 index 00000000..28a761ae --- /dev/null +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -0,0 +1,507 @@ +"use strict"; +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +var __assign = + (this && this.__assign) || + function () { + __assign = + Object.assign || + function (t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; +var __awaiter = + (this && this.__awaiter) || + function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P + ? value + : new P(function (resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; +var __generator = + (this && this.__generator) || + function (thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [], + }, + f, + y, + t, + g; + return ( + (g = { next: verb(0), throw: verb(1), return: verb(2) }), + typeof Symbol === "function" && + (g[Symbol.iterator] = function () { + return this; + }), + g + ); + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) + try { + if ( + ((f = 1), + y && + (t = + op[0] & 2 + ? y["return"] + : op[0] + ? y["throw"] || ((t = y["return"]) && t.call(y), 0) + : y.next) && + !(t = t.call(y, op[1])).done) + ) + return t; + if (((y = 0), t)) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { value: op[1], done: false }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if ( + !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && + (op[0] === 6 || op[0] === 2) + ) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + if (op[0] & 5) throw op[1]; + return { value: op[0] ? op[1] : void 0, done: true }; + } + }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getRecipeImplementation = void 0; +var querier_1 = require("../../querier"); +var recipe_1 = require("../multitenancy/recipe"); +function getRecipeImplementation(recipeImplInput) { + var querier = new querier_1.default(recipeImplInput.recipeId, recipeImplInput.appInfo); + return { + registerOptions: function (_a) { + var options = _a.options, + userContext = _a.userContext, + email = _a.email, + recoverAccountToken = _a.recoverAccountToken; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/webauthn/options/register", + { + body: JSON.stringify({ + email: email, + recoverAccountToken: recoverAccountToken, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "REGISTER_OPTIONS", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "REGISTER_OPTIONS", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + signInOptions: function (_a) { + var email = _a.email, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/webauthn/options/signin", + { + body: JSON.stringify({ + email: email, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_IN_OPTIONS", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_IN_OPTIONS", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + signUp: function (_a) { + var webauthnGeneratedOptionsId = _a.webauthnGeneratedOptionsId, + credential = _a.credential, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/webauthn/signup", + { + body: JSON.stringify({ + webauthnGeneratedOptionsId: webauthnGeneratedOptionsId, + credential: credential, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_UP", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_UP", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + signIn: function (_a) { + var webauthnGeneratedOptionsId = _a.webauthnGeneratedOptionsId, + credential = _a.credential, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/webauthn/signin", + { + body: JSON.stringify({ + webauthnGeneratedOptionsId: webauthnGeneratedOptionsId, + credential: credential, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "SIGN_IN", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "SIGN_IN", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + emailExists: function (_a) { + var email = _a.email, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).get; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/webauthn/email/exists", + {}, + { email: email }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "EMAIL_EXISTS", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "EMAIL_EXISTS", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + generateRecoverAccountToken: function (_a) { + var email = _a.email, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/user/webauthn/reset/token", + { + body: JSON.stringify({ + email: email, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "GENERATE_RECOVER_ACCOUNT_TOKEN", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "GENERATE_RECOVER_ACCOUNT_TOKEN", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + recoverAccount: function (_a) { + var token = _a.token, + webauthnGeneratedOptionsId = _a.webauthnGeneratedOptionsId, + credential = _a.credential, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var _b, jsonBody, fetchResponse, _c, _d; + return __generator(this, function (_e) { + switch (_e.label) { + case 0: + _d = (_c = querier).post; + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: userContext, + }), + ]; + case 1: + return [ + 4 /*yield*/, + _d.apply(_c, [ + _e.sent(), + "/user/webauthn/reset", + { + body: JSON.stringify({ + token: token, + webauthnGeneratedOptionsId: webauthnGeneratedOptionsId, + credential: credential, + }), + }, + querier_1.default.preparePreAPIHook({ + recipePreAPIHook: recipeImplInput.preAPIHook, + action: "RECOVER_ACCOUNT", + options: options, + userContext: userContext, + }), + querier_1.default.preparePostAPIHook({ + recipePostAPIHook: recipeImplInput.postAPIHook, + action: "RECOVER_ACCOUNT", + userContext: userContext, + }), + ]), + ]; + case 2: + (_b = _e.sent()), (jsonBody = _b.jsonBody), (fetchResponse = _b.fetchResponse); + return [2 /*return*/, __assign(__assign({}, jsonBody), { fetchResponse: fetchResponse })]; + } + }); + }); + }, + }; +} +exports.default = getRecipeImplementation; +exports.getRecipeImplementation = getRecipeImplementation; diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts new file mode 100644 index 00000000..fb4974ed --- /dev/null +++ b/lib/build/recipe/webauthn/types.d.ts @@ -0,0 +1,231 @@ +import { GeneralErrorResponse, User } from "../../types"; +import { + NormalisedInputType as AuthRecipeNormalisedInputType, + InputType as AuthRecipeInputType, +} from "../authRecipe/types"; +import { + RecipePostAPIHookContext, + RecipePreAPIHookContext, + UserInput as RecipeModuleUserInput, + RecipeFunctionOptions, +} from "../recipeModule/types"; +import OverrideableBuilder from "supertokens-js-override"; +export declare type PreAndPostAPIHookAction = + | "REGISTER_OPTIONS" + | "SIGN_IN_OPTIONS" + | "SIGN_UP" + | "SIGN_IN" + | "EMAIL_EXISTS" + | "GENERATE_RECOVER_ACCOUNT_TOKEN" + | "RECOVER_ACCOUNT"; +export declare type PreAPIHookContext = RecipePreAPIHookContext; +export declare type PostAPIHookContext = RecipePostAPIHookContext; +export declare type ResidentKey = "required" | "preferred" | "discouraged"; +export declare type UserVerification = "required" | "preferred" | "discouraged"; +export declare type UserInput = { + override?: { + functions?: ( + originalImplementation: RecipeInterface, + builder: OverrideableBuilder + ) => RecipeInterface; + }; +} & RecipeModuleUserInput; +export declare type InputType = AuthRecipeInputType & UserInput; +export declare type NormalisedInputType = AuthRecipeNormalisedInputType & { + override: { + functions: ( + originalImplementation: RecipeInterface, + builder: OverrideableBuilder + ) => RecipeInterface; + }; +}; +export declare type CredentialPayload = { + id: string; + rawId: string; + response: { + clientDataJSON: string; + attestationObject: string; + transports?: ("ble" | "cable" | "hybrid" | "internal" | "nfc" | "smart-card" | "usb")[]; + userHandle: string; + }; + authenticatorAttachment: "platform" | "cross-platform"; + clientExtensionResults: Record; + type: "public-key"; +}; +export declare type RecipeInterface = { + registerOptions: ( + input: { + options?: RecipeFunctionOptions; + userContext: any; + } & ( + | { + email: string; + } + | { + recoverAccountToken: string; + } + ) + ) => Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + >; + signInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + signUp: (input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + } + | { + status: "EMAIL_ALREADY_EXISTS_ERROR"; + } + >; + signIn: (input: { + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; + emailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >; + generateRecoverAccountToken: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + } + | { + status: "RECOVER_ACCOUNT_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; + recoverAccount: (input: { + token: string; + webauthnGeneratedOptionsId: string; + credential: CredentialPayload; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + email: string; + } + | GeneralErrorResponse + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + } + >; +}; diff --git a/lib/build/recipe/webauthn/types.js b/lib/build/recipe/webauthn/types.js new file mode 100644 index 00000000..9f123731 --- /dev/null +++ b/lib/build/recipe/webauthn/types.js @@ -0,0 +1,16 @@ +"use strict"; +/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/build/recipe/webauthn/utils.d.ts b/lib/build/recipe/webauthn/utils.d.ts new file mode 100644 index 00000000..0d9453eb --- /dev/null +++ b/lib/build/recipe/webauthn/utils.d.ts @@ -0,0 +1,2 @@ +import { InputType, NormalisedInputType } from "./types"; +export declare function normaliseUserInput(config: InputType): NormalisedInputType; diff --git a/lib/build/recipe/webauthn/utils.js b/lib/build/recipe/webauthn/utils.js new file mode 100644 index 00000000..574cdd9a --- /dev/null +++ b/lib/build/recipe/webauthn/utils.js @@ -0,0 +1,44 @@ +"use strict"; +var __assign = + (this && this.__assign) || + function () { + __assign = + Object.assign || + function (t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.normaliseUserInput = void 0; +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +var utils_1 = require("../authRecipe/utils"); +function normaliseUserInput(config) { + var override = __assign( + { + functions: function (originalImplementation) { + return originalImplementation; + }, + }, + config.override + ); + return __assign(__assign({}, (0, utils_1.normaliseAuthRecipe)(config)), { override: override }); +} +exports.normaliseUserInput = normaliseUserInput; diff --git a/lib/build/types.d.ts b/lib/build/types.d.ts index 2da11d6a..bf194deb 100644 --- a/lib/build/types.d.ts +++ b/lib/build/types.d.ts @@ -139,3 +139,8 @@ export declare type User = { }; }[]; }; +export declare type GeneralErrorResponse = { + status: "GENERAL_ERROR"; + message: string; + fetchResponse: Response; +}; diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index 71172a51..1e4af95d 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1,2 +1,2 @@ -export declare const package_version = "0.14.0"; +export declare const package_version = "0.15.0"; export declare const supported_fdi: string[]; diff --git a/lib/build/version.js b/lib/build/version.js index b8366786..10d0ee2f 100644 --- a/lib/build/version.js +++ b/lib/build/version.js @@ -15,5 +15,5 @@ exports.supported_fdi = exports.package_version = void 0; * License for the specific language governing permissions and limitations * under the License. */ -exports.package_version = "0.14.0"; +exports.package_version = "0.15.0"; exports.supported_fdi = ["3.1", "4.0"]; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index 18353b91..2b832b64 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,6 +12,6 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const package_version = "0.14.0"; +export const package_version = "0.15.0"; export const supported_fdi = ["3.1", "4.0"]; diff --git a/package-lock.json b/package-lock.json index 676be8f5..6d349d22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "supertokens-web-js", - "version": "0.14.0", + "version": "0.15.0", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index e2bb06cf..0f7ff5e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-web-js", - "version": "0.14.0", + "version": "0.15.0", "description": "SuperTokens SDK for vanilla JS for all recipes", "main": "./index.js", "scripts": { From 6854d4d70bde070dd6b0fd05d0077b52a94d96fb Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 10 Dec 2024 08:57:54 +0530 Subject: [PATCH 21/46] Add support for fetchResponse in types --- lib/build/recipe/webauthn/types.d.ts | 19 +++++++++++++++++ lib/ts/recipe/webauthn/types.ts | 31 +++++++++++++++++----------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index fb4974ed..d2efbe8b 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -135,27 +135,34 @@ export declare type RecipeInterface = { | { status: "OK"; user: User; + fetchResponse: Response; } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; } | { status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; + fetchResponse: Response; } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; + fetchResponse: Response; } >; signIn: (input: { @@ -167,13 +174,16 @@ export declare type RecipeInterface = { | { status: "OK"; user: User; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -181,6 +191,7 @@ export declare type RecipeInterface = { | { status: "OK"; exists: boolean; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -191,10 +202,12 @@ export declare type RecipeInterface = { }) => Promise< | { status: "OK"; + fetchResponse: Response; } | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -209,23 +222,29 @@ export declare type RecipeInterface = { status: "OK"; user: User; email: string; + fetchResponse: Response; } | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; } | { status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; + fetchResponse: Response; } >; }; diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 8d358cf1..89f0750f 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -151,17 +151,19 @@ export type RecipeInterface = { | { status: "OK"; user: User; + fetchResponse: Response; } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } - | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } - | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } - | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } >; signIn: (input: { webauthnGeneratedOptionsId: string; @@ -172,11 +174,13 @@ export type RecipeInterface = { | { status: "OK"; user: User; + fetchResponse: Response; } - | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -184,6 +188,7 @@ export type RecipeInterface = { | { status: "OK"; exists: boolean; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -194,8 +199,9 @@ export type RecipeInterface = { }) => Promise< | { status: "OK"; + fetchResponse: Response; } - | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } + | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string; fetchResponse: Response } | GeneralErrorResponse >; recoverAccount: (input: { @@ -209,12 +215,13 @@ export type RecipeInterface = { status: "OK"; user: User; email: string; + fetchResponse: Response; } | GeneralErrorResponse - | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } - | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } - | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; }; From 6403de1ba452615a705361cae9914f2816112672 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 10 Dec 2024 09:24:52 +0530 Subject: [PATCH 22/46] Add initial types for wrapper methods around webauthn methods --- lib/ts/recipe/webauthn/types.ts | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 89f0750f..390ab113 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -224,4 +224,75 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; + registerAndSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } + >; + authenticateAndSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + registerAndRecoverAccount: (input: { + recoverAccountToken: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + email: string; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + >; }; From 8a26ab1f78551b70d30f2ed3b7639ee5e30d07a4 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 10 Dec 2024 15:43:18 +0530 Subject: [PATCH 23/46] Add init code for handling registration with signup --- lib/ts/recipe/webauthn/recipeImplementation.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 54b6d2d2..4046bf3f 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -348,6 +348,17 @@ export default function getRecipeImplementation( fetchResponse, }; }, + registerAndSignUp: async function ({ email, options, userContext }) { + // Get the registration options by using the passed email ID. + const registrationOptions = await this.registerOptions({ options, userContext, email }); + if (registrationOptions?.status !== "OK") { + // If we did not get an OK status, we need to return the error as is. + return registrationOptions; + } + + // We should have received a valid registration options response. + // TODO: Pass the registration options to simplewebauthn + }, }; } From 98a116b2ee3279948f4a0078aa8551ddc87a5028 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 10 Dec 2024 18:47:58 +0530 Subject: [PATCH 24/46] Add init definition for handling registration and signup --- .../recipe/webauthn/recipeImplementation.ts | 41 ++++++++++++++++++- lib/ts/recipe/webauthn/types.ts | 1 + package-lock.json | 13 +++++- package.json | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 4046bf3f..5b0c08ac 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -19,6 +19,7 @@ import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModul import { PreAndPostAPIHookAction } from "./types"; import { GeneralErrorResponse, User } from "../../types"; import Multitenancy from "../multitenancy/recipe"; +import { RegistrationResponseJSON, startRegistration } from "@simplewebauthn/browser"; export default function getRecipeImplementation( recipeImplInput: RecipeImplementationInput @@ -353,11 +354,49 @@ export default function getRecipeImplementation( const registrationOptions = await this.registerOptions({ options, userContext, email }); if (registrationOptions?.status !== "OK") { // If we did not get an OK status, we need to return the error as is. + + // If the `status` is `RECOVER_ACCOUNT_TOKEN_INVALID_ERROR`, we need to throw an + // error since that should never happen as we are registering with an email + // and not a token. + if (registrationOptions?.status === "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR") { + throw new Error("Got `RECOVER_ACCOUNT_TOKEN_INVALID_ERROR` status that should never happen"); + } + return registrationOptions; } // We should have received a valid registration options response. - // TODO: Pass the registration options to simplewebauthn + let registrationResponse: RegistrationResponseJSON; + try { + registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); + } catch (error: any) { + if (error.name === "InvalidStateError") { + return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; + } + + throw error; + } + + // We should have a valid registration response for the passed credentials + // and we are good to go ahead and verify them. + return await this.signUp({ + webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, + credential: { + id: registrationResponse.id, + rawId: registrationResponse.rawId, + response: { + clientDataJSON: registrationResponse.response.clientDataJSON, + attestationObject: registrationResponse.response.attestationObject, + transports: registrationResponse.response.transports, + userHandle: "TBD", // TODO: Fetch from the response + }, + authenticatorAttachment: registrationResponse.authenticatorAttachment || "platform", // TODO: Fix acc to what Victor suggests + type: registrationResponse.type, + clientExtensionResults: {}, // TODO: Fetch from the response. + }, + options, + userContext, + }); }, }; } diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 390ab113..c7fb3149 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -250,6 +250,7 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } >; authenticateAndSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { diff --git a/package-lock.json b/package-lock.json index 6d349d22..ab64ae12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,9 +6,10 @@ "packages": { "": { "name": "supertokens-web-js", - "version": "0.14.0", + "version": "0.15.0", "license": "Apache-2.0", "dependencies": { + "@simplewebauthn/browser": "^13.0.0", "supertokens-js-override": "0.0.4", "supertokens-website": "^20.1.5" }, @@ -2218,6 +2219,11 @@ "node": ">= 8" } }, + "node_modules/@simplewebauthn/browser": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@simplewebauthn/browser/-/browser-13.0.0.tgz", + "integrity": "sha512-7d/+gxoFoDQxq2EkLl/PuTIQ/rnSrA3bmr8L2Ij7bRyicJoCJX/NDGUNExyctB9nSDrEkkcrJMDkwpCYOGU3Lg==" + }, "node_modules/@size-limit/esbuild": { "version": "8.2.6", "resolved": "https://registry.npmjs.org/@size-limit/esbuild/-/esbuild-8.2.6.tgz", @@ -12242,6 +12248,11 @@ "fastq": "^1.6.0" } }, + "@simplewebauthn/browser": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/@simplewebauthn/browser/-/browser-13.0.0.tgz", + "integrity": "sha512-7d/+gxoFoDQxq2EkLl/PuTIQ/rnSrA3bmr8L2Ij7bRyicJoCJX/NDGUNExyctB9nSDrEkkcrJMDkwpCYOGU3Lg==" + }, "@size-limit/esbuild": { "version": "8.2.6", "resolved": "https://registry.npmjs.org/@size-limit/esbuild/-/esbuild-8.2.6.tgz", diff --git a/package.json b/package.json index 0f7ff5e7..bfbcebe6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "homepage": "https://github.com/supertokens/supertokens-web-js#readme", "dependencies": { + "@simplewebauthn/browser": "^13.0.0", "supertokens-js-override": "0.0.4", "supertokens-website": "^20.1.5" }, From 0b7d1d41ad55d3d95a79155a7c84431f0285e911 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 18:23:48 +0530 Subject: [PATCH 25/46] Add type fixes for sign up and sign in credential payload --- .../recipe/webauthn/recipeImplementation.ts | 47 +++++++++++++------ lib/ts/recipe/webauthn/types.ts | 7 +-- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 5b0c08ac..0556e633 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -19,7 +19,12 @@ import { RecipeFunctionOptions, RecipeImplementationInput } from "../recipeModul import { PreAndPostAPIHookAction } from "./types"; import { GeneralErrorResponse, User } from "../../types"; import Multitenancy from "../multitenancy/recipe"; -import { RegistrationResponseJSON, startRegistration } from "@simplewebauthn/browser"; +import { + AuthenticationResponseJSON, + RegistrationResponseJSON, + startAuthentication, + startRegistration, +} from "@simplewebauthn/browser"; export default function getRecipeImplementation( recipeImplInput: RecipeImplementationInput @@ -381,23 +386,37 @@ export default function getRecipeImplementation( // and we are good to go ahead and verify them. return await this.signUp({ webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: { - id: registrationResponse.id, - rawId: registrationResponse.rawId, - response: { - clientDataJSON: registrationResponse.response.clientDataJSON, - attestationObject: registrationResponse.response.attestationObject, - transports: registrationResponse.response.transports, - userHandle: "TBD", // TODO: Fetch from the response - }, - authenticatorAttachment: registrationResponse.authenticatorAttachment || "platform", // TODO: Fix acc to what Victor suggests - type: registrationResponse.type, - clientExtensionResults: {}, // TODO: Fetch from the response. - }, + credential: registrationResponse, options, userContext, }); }, + authenticateAndSignIn: async function ({ email, options, userContext }) { + // Make a call to get the sign in options using the entered email ID. + const signInOptions = await this.signInOptions({ email, options, userContext }); + if (signInOptions?.status !== "OK") { + // We want to return the error as is if status was not "OK" + return signInOptions; + } + + // We should have the options ready and are good to start the authentication + let authenticationResponse: AuthenticationResponseJSON; + try { + authenticationResponse = await startAuthentication({ optionsJSON: signInOptions }); + } catch (error: any) { + // TODO: Do we need to do something with the error besides throwing it? + throw error; + } + + // We should have a valid authentication response at this point so we can + // go ahead and sign in the user. + return await this.signIn({ + webauthnGeneratedOptionsId: signInOptions.webauthnGeneratedOptionsId, + credential: authenticationResponse, + options: options, + userContext: userContext, + }); + }, }; } diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index c7fb3149..6d11f3d6 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -13,6 +13,7 @@ * under the License. */ +import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; import { GeneralErrorResponse, User } from "../../types"; import { NormalisedInputType as AuthRecipeNormalisedInputType, @@ -71,7 +72,7 @@ export type CredentialPayload = { userHandle: string; }; authenticatorAttachment: "platform" | "cross-platform"; - clientExtensionResults: Record; + clientExtensionResults: any; type: "public-key"; }; @@ -144,7 +145,7 @@ export type RecipeInterface = { >; signUp: (input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< @@ -167,7 +168,7 @@ export type RecipeInterface = { >; signIn: (input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< From 41da8ab5e194b9eddfe79a40be84cb0aada75bcd Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 18:37:32 +0530 Subject: [PATCH 26/46] Add support for registering and recovering account in recipe --- lib/ts/recipe/webauthn/index.ts | 5 ++- .../recipe/webauthn/recipeImplementation.ts | 37 +++++++++++++++++++ lib/ts/recipe/webauthn/types.ts | 3 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 9643144d..3630d399 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -13,6 +13,7 @@ * under the License. */ +import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; import { GeneralErrorResponse, User } from "../../types"; import { getNormalisedUserContext } from "../../utils"; import { RecipeFunctionOptions } from "../recipeModule/types"; @@ -144,7 +145,7 @@ export default class RecipeWrapper { */ static signUp(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< @@ -184,7 +185,7 @@ export default class RecipeWrapper { */ static signIn(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 0556e633..32040faa 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -417,6 +417,43 @@ export default function getRecipeImplementation( userContext: userContext, }); }, + registerAndRecoverAccount: async function ({ recoverAccountToken, options, userContext }) { + // Get the registration options based on the recoverAccountToken and + // register the device against the user. + const registrationOptions = await this.registerOptions({ options, userContext, recoverAccountToken }); + if (registrationOptions?.status !== "OK") { + // If we did not get an OK status, we need to return the error as is. + + // If the `status` is `INVALID_EMAIL_ERROR`, we need to throw an + // error since that should never happen as we are registering with a recover account token + // and not an email ID. + if (registrationOptions?.status === "INVALID_EMAIL_ERROR") { + throw new Error("Got `INVALID_EMAIL_ERROR` status that should never happen"); + } + + return registrationOptions; + } + + // We should have received a valid registration options response. + let registrationResponse: RegistrationResponseJSON; + try { + registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); + } catch (error: any) { + if (error.name === "InvalidStateError") { + return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; + } + + throw error; + } + + return await this.recoverAccount({ + token: recoverAccountToken, + webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, + credential: registrationResponse, + options, + userContext, + }); + }, }; } diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 6d11f3d6..f9391924 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -208,7 +208,7 @@ export type RecipeInterface = { recoverAccount: (input: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< @@ -296,5 +296,6 @@ export type RecipeInterface = { | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } >; }; From 04f3f575c21dc96512518b931384977acfc8a28d Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 18:54:02 +0530 Subject: [PATCH 27/46] Expose function for register and recover functionality --- lib/ts/recipe/webauthn/index.ts | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 3630d399..caa6c92c 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -297,6 +297,54 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * This function will handle getting registration options for the email ID, registering the user using + * webauthn and then signing up the user. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to register and signup + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static registerAndSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.registerAndSignUp({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -307,6 +355,7 @@ const signIn = RecipeWrapper.signIn; const emailExists = RecipeWrapper.emailExists; const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; const recoverAccount = RecipeWrapper.recoverAccount; +const registerAndSignup = RecipeWrapper.registerAndSignUp; export { init, @@ -317,4 +366,5 @@ export { emailExists, generateRecoverAccountToken, recoverAccount, + registerAndSignup, }; From 6054dcb6812576ab6b8acc86f47e9f4199db0627 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 19:10:08 +0530 Subject: [PATCH 28/46] Expose function for authentication and sign in through recipe --- lib/ts/recipe/webauthn/index.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index caa6c92c..18051037 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -345,6 +345,43 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Authenticate the user and sign them in after verifying their identity. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to authenticate and signin + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static authenticateAndSignIn(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | GeneralErrorResponse + > { + return Recipe.getInstanceOrThrow().recipeImplementation.authenticateAndSignIn({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -356,6 +393,7 @@ const emailExists = RecipeWrapper.emailExists; const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; const recoverAccount = RecipeWrapper.recoverAccount; const registerAndSignup = RecipeWrapper.registerAndSignUp; +const authenticateAndSignIn = RecipeWrapper.authenticateAndSignIn; export { init, @@ -367,4 +405,5 @@ export { generateRecoverAccountToken, recoverAccount, registerAndSignup, + authenticateAndSignIn, }; From 602c9af7f5f18133a96fbe6ae4b050a3238923a6 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 19:13:38 +0530 Subject: [PATCH 29/46] Expose function for registering and recovering users account --- lib/ts/recipe/webauthn/index.ts | 51 +++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 18051037..e3dd279d 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -299,8 +299,7 @@ export default class RecipeWrapper { } /** - * This function will handle getting registration options for the email ID, registering the user using - * webauthn and then signing up the user. + * Register the new device and signup the user with the passed email ID. * * It uses `@simplewebauthn/browser` to make the webauthn calls. * @@ -382,6 +381,52 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + /** + * Register the new device and recover the user's account with the recover token. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param recoverAccountToken Recovery token for the user's account + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static registerAndRecoverAccount(input: { + recoverAccountToken: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + email: string; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.registerAndRecoverAccount({ + ...input, + userContext: input?.userContext, + }); + } } const init = RecipeWrapper.init; @@ -394,6 +439,7 @@ const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; const recoverAccount = RecipeWrapper.recoverAccount; const registerAndSignup = RecipeWrapper.registerAndSignUp; const authenticateAndSignIn = RecipeWrapper.authenticateAndSignIn; +const registerAndRecoverAccount = RecipeWrapper.registerAndRecoverAccount; export { init, @@ -406,4 +452,5 @@ export { recoverAccount, registerAndSignup, authenticateAndSignIn, + registerAndRecoverAccount, }; From 24eb95f601af1e9b160cfea11ee2c35925acd45a Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 11 Dec 2024 19:16:24 +0530 Subject: [PATCH 30/46] Update changelog and create build --- CHANGELOG.md | 1 + lib/build/recipe/webauthn/index.d.ts | 162 ++++++++++++++- lib/build/recipe/webauthn/index.js | 71 ++++++- .../recipe/webauthn/recipeImplementation.js | 191 ++++++++++++++++++ lib/build/recipe/webauthn/types.d.ts | 121 ++++++++++- 5 files changed, 539 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e7c9133..6cce349e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.15.0] - 2024-12-10 - Added webauthn support for various functionalities +- Adds wrapper methods by using webauthn to provide ease of usage for passkeys ## [0.14.0] - 2024-10-07 diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 5b03ce99..699b9bc7 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -1,3 +1,4 @@ +import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; import { GeneralErrorResponse, User } from "../../types"; import { RecipeFunctionOptions } from "../recipeModule/types"; import { CredentialPayload, ResidentKey, UserInput, UserVerification } from "./types"; @@ -120,7 +121,7 @@ export default class RecipeWrapper { */ static signUp(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< @@ -165,7 +166,7 @@ export default class RecipeWrapper { */ static signIn(input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< @@ -270,6 +271,157 @@ export default class RecipeWrapper { reason: string; } >; + /** + * Register the new device and signup the user with the passed email ID. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to register and signup + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static registerAndSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + fetchResponse: Response; + } + | { + status: "EMAIL_ALREADY_EXISTS_ERROR"; + fetchResponse: Response; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + >; + /** + * Authenticate the user and sign them in after verifying their identity. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to authenticate and signin + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static authenticateAndSignIn(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + /** + * Register the new device and recover the user's account with the recover token. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param recoverAccountToken Recovery token for the user's account + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + static registerAndRecoverAccount(input: { + recoverAccountToken: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< + | { + status: "OK"; + user: User; + email: string; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + fetchResponse: Response; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + >; } declare const init: typeof RecipeWrapper.init; declare const registerOptions: typeof RecipeWrapper.registerOptions; @@ -279,6 +431,9 @@ declare const signIn: typeof RecipeWrapper.signIn; declare const emailExists: typeof RecipeWrapper.emailExists; declare const generateRecoverAccountToken: typeof RecipeWrapper.generateRecoverAccountToken; declare const recoverAccount: typeof RecipeWrapper.recoverAccount; +declare const registerAndSignup: typeof RecipeWrapper.registerAndSignUp; +declare const authenticateAndSignIn: typeof RecipeWrapper.authenticateAndSignIn; +declare const registerAndRecoverAccount: typeof RecipeWrapper.registerAndRecoverAccount; export { init, registerOptions, @@ -288,4 +443,7 @@ export { emailExists, generateRecoverAccountToken, recoverAccount, + registerAndSignup, + authenticateAndSignIn, + registerAndRecoverAccount, }; diff --git a/lib/build/recipe/webauthn/index.js b/lib/build/recipe/webauthn/index.js index cb5040eb..727280d8 100644 --- a/lib/build/recipe/webauthn/index.js +++ b/lib/build/recipe/webauthn/index.js @@ -28,7 +28,10 @@ var __assign = return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.recoverAccount = +exports.registerAndRecoverAccount = + exports.authenticateAndSignIn = + exports.registerAndSignup = + exports.recoverAccount = exports.generateRecoverAccountToken = exports.emailExists = exports.signIn = @@ -187,6 +190,66 @@ var RecipeWrapper = /** @class */ (function () { }) ); }; + /** + * Register the new device and signup the user with the passed email ID. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to register and signup + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + RecipeWrapper.registerAndSignUp = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerAndSignUp( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Authenticate the user and sign them in after verifying their identity. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param email Email of the user to authenticate and signin + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + RecipeWrapper.authenticateAndSignIn = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.authenticateAndSignIn( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; + /** + * Register the new device and recover the user's account with the recover token. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param recoverAccountToken Recovery token for the user's account + * + * @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation} + * + * @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks) + * + * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email + */ + RecipeWrapper.registerAndRecoverAccount = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerAndRecoverAccount( + __assign(__assign({}, input), { + userContext: input === null || input === void 0 ? void 0 : input.userContext, + }) + ); + }; return RecipeWrapper; })(); exports.default = RecipeWrapper; @@ -206,3 +269,9 @@ var generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; exports.generateRecoverAccountToken = generateRecoverAccountToken; var recoverAccount = RecipeWrapper.recoverAccount; exports.recoverAccount = recoverAccount; +var registerAndSignup = RecipeWrapper.registerAndSignUp; +exports.registerAndSignup = registerAndSignup; +var authenticateAndSignIn = RecipeWrapper.authenticateAndSignIn; +exports.authenticateAndSignIn = authenticateAndSignIn; +var registerAndRecoverAccount = RecipeWrapper.registerAndRecoverAccount; +exports.registerAndRecoverAccount = registerAndRecoverAccount; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js index 28a761ae..1e55a097 100644 --- a/lib/build/recipe/webauthn/recipeImplementation.js +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -162,6 +162,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getRecipeImplementation = void 0; var querier_1 = require("../../querier"); var recipe_1 = require("../multitenancy/recipe"); +var browser_1 = require("@simplewebauthn/browser"); function getRecipeImplementation(recipeImplInput) { var querier = new querier_1.default(recipeImplInput.recipeId, recipeImplInput.appInfo); return { @@ -501,6 +502,196 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, + registerAndSignUp: function (_a) { + var email = _a.email, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var registrationOptions, registrationResponse, error_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + return [ + 4 /*yield*/, + this.registerOptions({ options: options, userContext: userContext, email: email }), + ]; + case 1: + registrationOptions = _b.sent(); + if ( + (registrationOptions === null || registrationOptions === void 0 + ? void 0 + : registrationOptions.status) !== "OK" + ) { + // If we did not get an OK status, we need to return the error as is. + // If the `status` is `RECOVER_ACCOUNT_TOKEN_INVALID_ERROR`, we need to throw an + // error since that should never happen as we are registering with an email + // and not a token. + if ( + (registrationOptions === null || registrationOptions === void 0 + ? void 0 + : registrationOptions.status) === "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" + ) { + throw new Error( + "Got `RECOVER_ACCOUNT_TOKEN_INVALID_ERROR` status that should never happen" + ); + } + return [2 /*return*/, registrationOptions]; + } + _b.label = 2; + case 2: + _b.trys.push([2, 4, , 5]); + return [ + 4 /*yield*/, + (0, browser_1.startRegistration)({ optionsJSON: registrationOptions }), + ]; + case 3: + registrationResponse = _b.sent(); + return [3 /*break*/, 5]; + case 4: + error_1 = _b.sent(); + if (error_1.name === "InvalidStateError") { + return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; + } + throw error_1; + case 5: + return [ + 4 /*yield*/, + this.signUp({ + webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, + credential: registrationResponse, + options: options, + userContext: userContext, + }), + ]; + case 6: + // We should have a valid registration response for the passed credentials + // and we are good to go ahead and verify them. + return [2 /*return*/, _b.sent()]; + } + }); + }); + }, + authenticateAndSignIn: function (_a) { + var email = _a.email, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var signInOptions, authenticationResponse, error_2; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + return [ + 4 /*yield*/, + this.signInOptions({ email: email, options: options, userContext: userContext }), + ]; + case 1: + signInOptions = _b.sent(); + if ( + (signInOptions === null || signInOptions === void 0 ? void 0 : signInOptions.status) !== + "OK" + ) { + // We want to return the error as is if status was not "OK" + return [2 /*return*/, signInOptions]; + } + _b.label = 2; + case 2: + _b.trys.push([2, 4, , 5]); + return [4 /*yield*/, (0, browser_1.startAuthentication)({ optionsJSON: signInOptions })]; + case 3: + authenticationResponse = _b.sent(); + return [3 /*break*/, 5]; + case 4: + error_2 = _b.sent(); + // TODO: Do we need to do something with the error besides throwing it? + throw error_2; + case 5: + return [ + 4 /*yield*/, + this.signIn({ + webauthnGeneratedOptionsId: signInOptions.webauthnGeneratedOptionsId, + credential: authenticationResponse, + options: options, + userContext: userContext, + }), + ]; + case 6: + // We should have a valid authentication response at this point so we can + // go ahead and sign in the user. + return [2 /*return*/, _b.sent()]; + } + }); + }); + }, + registerAndRecoverAccount: function (_a) { + var recoverAccountToken = _a.recoverAccountToken, + options = _a.options, + userContext = _a.userContext; + return __awaiter(this, void 0, void 0, function () { + var registrationOptions, registrationResponse, error_3; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + return [ + 4 /*yield*/, + this.registerOptions({ + options: options, + userContext: userContext, + recoverAccountToken: recoverAccountToken, + }), + ]; + case 1: + registrationOptions = _b.sent(); + if ( + (registrationOptions === null || registrationOptions === void 0 + ? void 0 + : registrationOptions.status) !== "OK" + ) { + // If we did not get an OK status, we need to return the error as is. + // If the `status` is `INVALID_EMAIL_ERROR`, we need to throw an + // error since that should never happen as we are registering with a recover account token + // and not an email ID. + if ( + (registrationOptions === null || registrationOptions === void 0 + ? void 0 + : registrationOptions.status) === "INVALID_EMAIL_ERROR" + ) { + throw new Error("Got `INVALID_EMAIL_ERROR` status that should never happen"); + } + return [2 /*return*/, registrationOptions]; + } + _b.label = 2; + case 2: + _b.trys.push([2, 4, , 5]); + return [ + 4 /*yield*/, + (0, browser_1.startRegistration)({ optionsJSON: registrationOptions }), + ]; + case 3: + registrationResponse = _b.sent(); + return [3 /*break*/, 5]; + case 4: + error_3 = _b.sent(); + if (error_3.name === "InvalidStateError") { + return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; + } + throw error_3; + case 5: + return [ + 4 /*yield*/, + this.recoverAccount({ + token: recoverAccountToken, + webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, + credential: registrationResponse, + options: options, + userContext: userContext, + }), + ]; + case 6: + return [2 /*return*/, _b.sent()]; + } + }); + }); + }, }; } exports.default = getRecipeImplementation; diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index d2efbe8b..fd7a0986 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -1,3 +1,4 @@ +import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; import { GeneralErrorResponse, User } from "../../types"; import { NormalisedInputType as AuthRecipeNormalisedInputType, @@ -49,7 +50,7 @@ export declare type CredentialPayload = { userHandle: string; }; authenticatorAttachment: "platform" | "cross-platform"; - clientExtensionResults: Record; + clientExtensionResults: any; type: "public-key"; }; export declare type RecipeInterface = { @@ -128,7 +129,7 @@ export declare type RecipeInterface = { >; signUp: (input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< @@ -167,7 +168,7 @@ export declare type RecipeInterface = { >; signIn: (input: { webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: AuthenticationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< @@ -214,7 +215,7 @@ export declare type RecipeInterface = { recoverAccount: (input: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }) => Promise< @@ -247,4 +248,116 @@ export declare type RecipeInterface = { fetchResponse: Response; } >; + registerAndSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_EMAIL_ERROR"; + err: string; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "SIGN_UP_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + fetchResponse: Response; + } + | { + status: "EMAIL_ALREADY_EXISTS_ERROR"; + fetchResponse: Response; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + >; + authenticateAndSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | { + status: "OK"; + user: User; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "SIGN_IN_NOT_ALLOWED"; + reason: string; + fetchResponse: Response; + } + | GeneralErrorResponse + >; + registerAndRecoverAccount: (input: { + recoverAccountToken: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< + | { + status: "OK"; + user: User; + email: string; + fetchResponse: Response; + } + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | GeneralErrorResponse + | { + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; + } + | { + status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_AUTHENTICATOR_ERROR"; + reason: string; + fetchResponse: Response; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + >; }; From a9de691bde3fdcf353fd1d9edfab22523c8b6c99 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 16 Dec 2024 15:01:08 +0530 Subject: [PATCH 31/46] Fix some duplicate errors --- lib/ts/recipe/webauthn/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index f9391924..4b5873ec 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -248,7 +248,6 @@ export type RecipeInterface = { } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } @@ -294,7 +293,6 @@ export type RecipeInterface = { | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } >; From 439fe7cd35c2071a5587858a2417ffbe5719a848 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 17 Dec 2024 09:13:38 +0530 Subject: [PATCH 32/46] Update function names to be more informative --- lib/ts/recipe/webauthn/index.ts | 52 ++++++++++--------- .../recipe/webauthn/recipeImplementation.ts | 18 +++---- lib/ts/recipe/webauthn/types.ts | 16 +++--- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index e3dd279d..54246c74 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -39,7 +39,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) */ - static registerOptions( + static getRegisterOptions( input: { options?: RecipeFunctionOptions; userContext: any } & ( | { email: string } | { recoverAccountToken: string } @@ -90,7 +90,7 @@ export default class RecipeWrapper { fetchResponse: Response; } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerOptions({ + return Recipe.getInstanceOrThrow().recipeImplementation.getRegisterOptions({ ...input, userContext: getNormalisedUserContext(input?.userContext), }); @@ -108,7 +108,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - static signInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getSignInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -123,7 +123,7 @@ export default class RecipeWrapper { } | GeneralErrorResponse > { - return Recipe.getInstanceOrThrow().recipeImplementation.signInOptions({ + return Recipe.getInstanceOrThrow().recipeImplementation.getSignInOptions({ ...input, userContext: getNormalisedUserContext(input?.userContext), }); @@ -217,14 +217,14 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence */ - static emailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getEmailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; exists: boolean; } | GeneralErrorResponse > { - return Recipe.getInstanceOrThrow().recipeImplementation.emailExists({ + return Recipe.getInstanceOrThrow().recipeImplementation.getEmailExists({ ...input, userContext: input?.userContext, }); @@ -311,7 +311,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerAndSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static registerUserWithSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; user: User; @@ -339,7 +339,7 @@ export default class RecipeWrapper { | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerAndSignUp({ + return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithSignUp({ ...input, userContext: input?.userContext, }); @@ -358,7 +358,11 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static authenticateAndSignIn(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static authenticateUserWithSignIn(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< | { status: "OK"; user: User; @@ -376,7 +380,7 @@ export default class RecipeWrapper { } | GeneralErrorResponse > { - return Recipe.getInstanceOrThrow().recipeImplementation.authenticateAndSignIn({ + return Recipe.getInstanceOrThrow().recipeImplementation.authenticateUserWithSignIn({ ...input, userContext: input?.userContext, }); @@ -395,7 +399,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerAndRecoverAccount(input: { + static registerUserWithRecoverAccount(input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; @@ -422,7 +426,7 @@ export default class RecipeWrapper { | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerAndRecoverAccount({ + return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithRecoverAccount({ ...input, userContext: input?.userContext, }); @@ -430,27 +434,27 @@ export default class RecipeWrapper { } const init = RecipeWrapper.init; -const registerOptions = RecipeWrapper.registerOptions; -const signInOptions = RecipeWrapper.signInOptions; +const getRegisterOptions = RecipeWrapper.getRegisterOptions; +const getSignInOptions = RecipeWrapper.getSignInOptions; const signUp = RecipeWrapper.signUp; const signIn = RecipeWrapper.signIn; -const emailExists = RecipeWrapper.emailExists; +const getEmailExists = RecipeWrapper.getEmailExists; const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; const recoverAccount = RecipeWrapper.recoverAccount; -const registerAndSignup = RecipeWrapper.registerAndSignUp; -const authenticateAndSignIn = RecipeWrapper.authenticateAndSignIn; -const registerAndRecoverAccount = RecipeWrapper.registerAndRecoverAccount; +const registerUserWithSignUp = RecipeWrapper.registerUserWithSignUp; +const authenticateUserWithSignIn = RecipeWrapper.authenticateUserWithSignIn; +const registerUserWithRecoverAccount = RecipeWrapper.registerUserWithRecoverAccount; export { init, - registerOptions, - signInOptions, + getRegisterOptions, + getSignInOptions, signUp, signIn, - emailExists, + getEmailExists, generateRecoverAccountToken, recoverAccount, - registerAndSignup, - authenticateAndSignIn, - registerAndRecoverAccount, + registerUserWithSignUp, + authenticateUserWithSignIn, + registerUserWithRecoverAccount, }; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 32040faa..a27b1c13 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -32,7 +32,7 @@ export default function getRecipeImplementation( const querier = new Querier(recipeImplInput.recipeId, recipeImplInput.appInfo); return { - registerOptions: async function ({ + getRegisterOptions: async function ({ options, userContext, email, @@ -115,7 +115,7 @@ export default function getRecipeImplementation( fetchResponse, }; }, - signInOptions: async function ({ email, options, userContext }) { + getSignInOptions: async function ({ email, options, userContext }) { const { jsonBody, fetchResponse } = await querier.post< | { status: "OK"; @@ -244,7 +244,7 @@ export default function getRecipeImplementation( fetchResponse, }; }, - emailExists: async function ({ email, options, userContext }) { + getEmailExists: async function ({ email, options, userContext }) { const { jsonBody, fetchResponse } = await querier.get< | { status: "OK"; @@ -354,9 +354,9 @@ export default function getRecipeImplementation( fetchResponse, }; }, - registerAndSignUp: async function ({ email, options, userContext }) { + registerUserWithSignUp: async function ({ email, options, userContext }) { // Get the registration options by using the passed email ID. - const registrationOptions = await this.registerOptions({ options, userContext, email }); + const registrationOptions = await this.getRegisterOptions({ options, userContext, email }); if (registrationOptions?.status !== "OK") { // If we did not get an OK status, we need to return the error as is. @@ -391,9 +391,9 @@ export default function getRecipeImplementation( userContext, }); }, - authenticateAndSignIn: async function ({ email, options, userContext }) { + authenticateUserWithSignIn: async function ({ email, options, userContext }) { // Make a call to get the sign in options using the entered email ID. - const signInOptions = await this.signInOptions({ email, options, userContext }); + const signInOptions = await this.getSignInOptions({ email, options, userContext }); if (signInOptions?.status !== "OK") { // We want to return the error as is if status was not "OK" return signInOptions; @@ -417,10 +417,10 @@ export default function getRecipeImplementation( userContext: userContext, }); }, - registerAndRecoverAccount: async function ({ recoverAccountToken, options, userContext }) { + registerUserWithRecoverAccount: async function ({ recoverAccountToken, options, userContext }) { // Get the registration options based on the recoverAccountToken and // register the device against the user. - const registrationOptions = await this.registerOptions({ options, userContext, recoverAccountToken }); + const registrationOptions = await this.getRegisterOptions({ options, userContext, recoverAccountToken }); if (registrationOptions?.status !== "OK") { // If we did not get an OK status, we need to return the error as is. diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 4b5873ec..6c2767e6 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -77,7 +77,7 @@ export type CredentialPayload = { }; export type RecipeInterface = { - registerOptions: ( + getRegisterOptions: ( input: { options?: RecipeFunctionOptions; userContext: any } & ( | { email: string } | { recoverAccountToken: string } @@ -128,7 +128,7 @@ export type RecipeInterface = { fetchResponse: Response; } >; - signInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + getSignInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -185,7 +185,7 @@ export type RecipeInterface = { } | GeneralErrorResponse >; - emailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + getEmailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; exists: boolean; @@ -225,7 +225,7 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; - registerAndSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + registerUserWithSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; user: User; @@ -252,7 +252,11 @@ export type RecipeInterface = { | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } >; - authenticateAndSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + authenticateUserWithSignIn: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< | { status: "OK"; user: User; @@ -270,7 +274,7 @@ export type RecipeInterface = { } | GeneralErrorResponse >; - registerAndRecoverAccount: (input: { + registerUserWithRecoverAccount: (input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; From 05a3e370d12c206e0564cdaeb367a777d300905b Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 17 Dec 2024 11:41:21 +0530 Subject: [PATCH 33/46] Refactor native registrater user functionality into separate function --- lib/ts/recipe/webauthn/index.ts | 2 + .../recipe/webauthn/recipeImplementation.ts | 48 +++++++----- lib/ts/recipe/webauthn/types.ts | 74 +++++++++++-------- 3 files changed, 73 insertions(+), 51 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 54246c74..99041d84 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -338,6 +338,7 @@ export default class RecipeWrapper { | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithSignUp({ ...input, @@ -425,6 +426,7 @@ export default class RecipeWrapper { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithRecoverAccount({ ...input, diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index a27b1c13..846fcf2e 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -354,6 +354,26 @@ export default function getRecipeImplementation( fetchResponse, }; }, + registerUser: async function ({ registrationOptions }) { + let registrationResponse: RegistrationResponseJSON; + try { + registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); + } catch (error: any) { + if (error.name === "InvalidStateError") { + return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; + } + + return { + status: "FAILED_TO_REGISTER_USER", + error: error, + }; + } + + return { + status: "OK", + registrationResponse, + }; + }, registerUserWithSignUp: async function ({ email, options, userContext }) { // Get the registration options by using the passed email ID. const registrationOptions = await this.getRegisterOptions({ options, userContext, email }); @@ -371,22 +391,16 @@ export default function getRecipeImplementation( } // We should have received a valid registration options response. - let registrationResponse: RegistrationResponseJSON; - try { - registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); - } catch (error: any) { - if (error.name === "InvalidStateError") { - return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; - } - - throw error; + const registerUserResponse = await this.registerUser({ registrationOptions }); + if (registerUserResponse.status !== "OK") { + return registerUserResponse; } // We should have a valid registration response for the passed credentials // and we are good to go ahead and verify them. return await this.signUp({ webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registrationResponse, + credential: registerUserResponse.registrationResponse, options, userContext, }); @@ -435,21 +449,15 @@ export default function getRecipeImplementation( } // We should have received a valid registration options response. - let registrationResponse: RegistrationResponseJSON; - try { - registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); - } catch (error: any) { - if (error.name === "InvalidStateError") { - return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; - } - - throw error; + const registerUserResponse = await this.registerUser({ registrationOptions }); + if (registerUserResponse.status !== "OK") { + return registerUserResponse; } return await this.recoverAccount({ token: recoverAccountToken, webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registrationResponse, + credential: registerUserResponse.registrationResponse, options, userContext, }); diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 6c2767e6..4f9a8464 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -76,6 +76,38 @@ export type CredentialPayload = { type: "public-key"; }; +export type RegisterOptions = { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; +}; + export type RecipeInterface = { getRegisterOptions: ( input: { options?: RecipeFunctionOptions; userContext: any } & ( @@ -83,37 +115,7 @@ export type RecipeInterface = { | { recoverAccountToken: string } ) ) => Promise< - | { - status: "OK"; - webauthnGeneratedOptionsId: string; - rp: { - id: string; - name: string; - }; - user: { - id: string; - name: string; - displayName: string; - }; - challenge: string; - timeout: number; - excludeCredentials: { - id: string; - type: "public-key"; - transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; - }[]; - attestation: "none" | "indirect" | "direct" | "enterprise"; - pubKeyCredParams: { - alg: number; - type: "public-key"; - }[]; - authenticatorSelection: { - requireResidentKey: boolean; - residentKey: ResidentKey; - userVerification: UserVerification; - }; - fetchResponse: Response; - } + | RegisterOptions | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response; @@ -225,6 +227,14 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; + registerUser: (input: { registrationOptions: RegisterOptions }) => Promise< + | { + status: "OK"; + registrationResponse: RegistrationResponseJSON; + } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } + >; registerUserWithSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; @@ -251,6 +261,7 @@ export type RecipeInterface = { | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } >; authenticateUserWithSignIn: (input: { email: string; @@ -299,5 +310,6 @@ export type RecipeInterface = { | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } >; }; From 4d88f225a088295c0c8a300a505aeb83a6d39d5b Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 17 Dec 2024 11:47:23 +0530 Subject: [PATCH 34/46] Refactor authentication into it's separate function for overriding --- lib/ts/recipe/webauthn/index.ts | 1 + .../recipe/webauthn/recipeImplementation.ts | 27 ++++++++++++---- lib/ts/recipe/webauthn/types.ts | 32 ++++++++++++------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 99041d84..3b2a042b 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -379,6 +379,7 @@ export default class RecipeWrapper { reason: string; fetchResponse: Response; } + | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } | GeneralErrorResponse > { return Recipe.getInstanceOrThrow().recipeImplementation.authenticateUserWithSignIn({ diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 846fcf2e..f62f0028 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -405,6 +405,22 @@ export default function getRecipeImplementation( userContext, }); }, + authenticateUser: async function ({ authenticationOptions }) { + let authenticationResponse: AuthenticationResponseJSON; + try { + authenticationResponse = await startAuthentication({ optionsJSON: authenticationOptions }); + } catch (error: any) { + return { + status: "FAILED_TO_AUTHENTICATE_USER", + error: error, + }; + } + + return { + status: "OK", + authenticationResponse: authenticationResponse, + }; + }, authenticateUserWithSignIn: async function ({ email, options, userContext }) { // Make a call to get the sign in options using the entered email ID. const signInOptions = await this.getSignInOptions({ email, options, userContext }); @@ -414,19 +430,16 @@ export default function getRecipeImplementation( } // We should have the options ready and are good to start the authentication - let authenticationResponse: AuthenticationResponseJSON; - try { - authenticationResponse = await startAuthentication({ optionsJSON: signInOptions }); - } catch (error: any) { - // TODO: Do we need to do something with the error besides throwing it? - throw error; + const authenticateUserResponse = await this.authenticateUser({ authenticationOptions: signInOptions }); + if (authenticateUserResponse.status !== "OK") { + return authenticateUserResponse; } // We should have a valid authentication response at this point so we can // go ahead and sign in the user. return await this.signIn({ webauthnGeneratedOptionsId: signInOptions.webauthnGeneratedOptionsId, - credential: authenticationResponse, + credential: authenticateUserResponse.authenticationResponse, options: options, userContext: userContext, }); diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 4f9a8464..5a8ac1ce 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -76,7 +76,7 @@ export type CredentialPayload = { type: "public-key"; }; -export type RegisterOptions = { +export type RegistrationOptions = { status: "OK"; webauthnGeneratedOptionsId: string; rp: { @@ -108,6 +108,15 @@ export type RegisterOptions = { fetchResponse: Response; }; +export type AuthenticationOptions = { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; +}; + export type RecipeInterface = { getRegisterOptions: ( input: { options?: RecipeFunctionOptions; userContext: any } & ( @@ -115,7 +124,7 @@ export type RecipeInterface = { | { recoverAccountToken: string } ) ) => Promise< - | RegisterOptions + | RegistrationOptions | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response; @@ -131,14 +140,7 @@ export type RecipeInterface = { } >; getSignInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< - | { - status: "OK"; - webauthnGeneratedOptionsId: string; - challenge: string; - timeout: number; - userVerification: UserVerification; - fetchResponse: Response; - } + | AuthenticationOptions | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response; @@ -227,7 +229,7 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; - registerUser: (input: { registrationOptions: RegisterOptions }) => Promise< + registerUser: (input: { registrationOptions: RegistrationOptions }) => Promise< | { status: "OK"; registrationResponse: RegistrationResponseJSON; @@ -235,6 +237,13 @@ export type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } >; + authenticateUser: (input: { authenticationOptions: AuthenticationOptions }) => Promise< + | { + status: "OK"; + authenticationResponse: AuthenticationResponseJSON; + } + | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + >; registerUserWithSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; @@ -283,6 +292,7 @@ export type RecipeInterface = { reason: string; fetchResponse: Response; } + | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } | GeneralErrorResponse >; registerUserWithRecoverAccount: (input: { From f7099301fd79d905ed04cf844b7207eb66e557a8 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 17 Dec 2024 11:58:15 +0530 Subject: [PATCH 35/46] Make registerUser an exported function of webauthn recipe --- lib/ts/recipe/webauthn/index.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 3b2a042b..a8af1918 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -18,7 +18,7 @@ import { GeneralErrorResponse, User } from "../../types"; import { getNormalisedUserContext } from "../../utils"; import { RecipeFunctionOptions } from "../recipeModule/types"; import Recipe from "./recipe"; -import { CredentialPayload, ResidentKey, UserInput, UserVerification } from "./types"; +import { CredentialPayload, ResidentKey, UserInput, UserVerification, RegistrationOptions } from "./types"; export default class RecipeWrapper { static init(config?: UserInput) { @@ -298,6 +298,26 @@ export default class RecipeWrapper { }); } + /** + * Register user with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param registrationOptions Options to pass for the registration. + * + * @returns `{ status: "OK", ...}` if successful along with registration response received + */ + static registerUser(input: { registrationOptions: RegistrationOptions }): Promise< + | { + status: "OK"; + registrationResponse: RegistrationResponseJSON; + } + | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } + | { status: "FAILED_TO_REGISTER_USER"; error: any } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.registerUser(input); + } + /** * Register the new device and signup the user with the passed email ID. * @@ -447,6 +467,7 @@ const recoverAccount = RecipeWrapper.recoverAccount; const registerUserWithSignUp = RecipeWrapper.registerUserWithSignUp; const authenticateUserWithSignIn = RecipeWrapper.authenticateUserWithSignIn; const registerUserWithRecoverAccount = RecipeWrapper.registerUserWithRecoverAccount; +const registerUser = RecipeWrapper.registerUser; export { init, @@ -460,4 +481,5 @@ export { registerUserWithSignUp, authenticateUserWithSignIn, registerUserWithRecoverAccount, + registerUser, }; From e38fff89138e30d28ca7d363c51010de2d87b565 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Tue, 17 Dec 2024 12:01:58 +0530 Subject: [PATCH 36/46] Expose function for authentication through webauthn recipe --- lib/ts/recipe/webauthn/index.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index a8af1918..36b3860b 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -18,7 +18,14 @@ import { GeneralErrorResponse, User } from "../../types"; import { getNormalisedUserContext } from "../../utils"; import { RecipeFunctionOptions } from "../recipeModule/types"; import Recipe from "./recipe"; -import { CredentialPayload, ResidentKey, UserInput, UserVerification, RegistrationOptions } from "./types"; +import { + CredentialPayload, + ResidentKey, + UserInput, + UserVerification, + RegistrationOptions, + AuthenticationOptions, +} from "./types"; export default class RecipeWrapper { static init(config?: UserInput) { @@ -318,6 +325,25 @@ export default class RecipeWrapper { return Recipe.getInstanceOrThrow().recipeImplementation.registerUser(input); } + /** + * Authenticate the user with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param authenticationOptions Options to pass for the authentication. + * + * @returns `{ status: "OK", ...}` if successful along with authentication response received + */ + static authenticateUser(input: { authenticationOptions: AuthenticationOptions }): Promise< + | { + status: "OK"; + authenticationResponse: AuthenticationResponseJSON; + } + | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.authenticateUser(input); + } + /** * Register the new device and signup the user with the passed email ID. * @@ -468,6 +494,7 @@ const registerUserWithSignUp = RecipeWrapper.registerUserWithSignUp; const authenticateUserWithSignIn = RecipeWrapper.authenticateUserWithSignIn; const registerUserWithRecoverAccount = RecipeWrapper.registerUserWithRecoverAccount; const registerUser = RecipeWrapper.registerUser; +const authenticateUser = RecipeWrapper.authenticateUser; export { init, @@ -482,4 +509,5 @@ export { authenticateUserWithSignIn, registerUserWithRecoverAccount, registerUser, + authenticateUser, }; From dbe0aa283fa41be87c6367df46167582359c54ab Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 18 Dec 2024 09:19:10 +0530 Subject: [PATCH 37/46] Rename some functions to more align with the actual functionality --- lib/ts/recipe/webauthn/index.ts | 48 ++++++++++--------- .../recipe/webauthn/recipeImplementation.ts | 36 +++++++------- lib/ts/recipe/webauthn/types.ts | 14 ++++-- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 36b3860b..d943f20c 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -306,7 +306,7 @@ export default class RecipeWrapper { } /** - * Register user with the passed options by using native webauthn functions. + * Register credential with the passed options by using native webauthn functions. * * It uses `@simplewebauthn/browser` to make the webauthn calls. * @@ -314,7 +314,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along with registration response received */ - static registerUser(input: { registrationOptions: RegistrationOptions }): Promise< + static registerCredential(input: { registrationOptions: RegistrationOptions }): Promise< | { status: "OK"; registrationResponse: RegistrationResponseJSON; @@ -322,11 +322,11 @@ export default class RecipeWrapper { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerUser(input); + return Recipe.getInstanceOrThrow().recipeImplementation.registerCredential(input); } /** - * Authenticate the user with the passed options by using native webauthn functions. + * Authenticate the credential with the passed options by using native webauthn functions. * * It uses `@simplewebauthn/browser` to make the webauthn calls. * @@ -334,14 +334,14 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along with authentication response received */ - static authenticateUser(input: { authenticationOptions: AuthenticationOptions }): Promise< + static authenticateCredential(input: { authenticationOptions: AuthenticationOptions }): Promise< | { status: "OK"; authenticationResponse: AuthenticationResponseJSON; } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } > { - return Recipe.getInstanceOrThrow().recipeImplementation.authenticateUser(input); + return Recipe.getInstanceOrThrow().recipeImplementation.authenticateCredential(input); } /** @@ -357,7 +357,11 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerUserWithSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static registerCredentialWithSignUp(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< | { status: "OK"; user: User; @@ -386,7 +390,7 @@ export default class RecipeWrapper { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithSignUp({ + return Recipe.getInstanceOrThrow().recipeImplementation.registerCredentialWithSignUp({ ...input, userContext: input?.userContext, }); @@ -405,7 +409,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static authenticateUserWithSignIn(input: { + static authenticateCredentialWithSignIn(input: { email: string; options?: RecipeFunctionOptions; userContext: any; @@ -428,7 +432,7 @@ export default class RecipeWrapper { | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } | GeneralErrorResponse > { - return Recipe.getInstanceOrThrow().recipeImplementation.authenticateUserWithSignIn({ + return Recipe.getInstanceOrThrow().recipeImplementation.authenticateCredentialWithSignIn({ ...input, userContext: input?.userContext, }); @@ -447,7 +451,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerUserWithRecoverAccount(input: { + static registerCredentialWithRecoverAccount(input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; @@ -475,7 +479,7 @@ export default class RecipeWrapper { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } > { - return Recipe.getInstanceOrThrow().recipeImplementation.registerUserWithRecoverAccount({ + return Recipe.getInstanceOrThrow().recipeImplementation.registerCredentialWithRecoverAccount({ ...input, userContext: input?.userContext, }); @@ -490,11 +494,11 @@ const signIn = RecipeWrapper.signIn; const getEmailExists = RecipeWrapper.getEmailExists; const generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; const recoverAccount = RecipeWrapper.recoverAccount; -const registerUserWithSignUp = RecipeWrapper.registerUserWithSignUp; -const authenticateUserWithSignIn = RecipeWrapper.authenticateUserWithSignIn; -const registerUserWithRecoverAccount = RecipeWrapper.registerUserWithRecoverAccount; -const registerUser = RecipeWrapper.registerUser; -const authenticateUser = RecipeWrapper.authenticateUser; +const registerCredentialWithSignUp = RecipeWrapper.registerCredentialWithSignUp; +const authenticateCredentialWithSignIn = RecipeWrapper.authenticateCredentialWithSignIn; +const registerCredentialWithRecoverAccount = RecipeWrapper.registerCredentialWithRecoverAccount; +const registerCredential = RecipeWrapper.registerCredential; +const authenticateCredential = RecipeWrapper.authenticateCredential; export { init, @@ -505,9 +509,9 @@ export { getEmailExists, generateRecoverAccountToken, recoverAccount, - registerUserWithSignUp, - authenticateUserWithSignIn, - registerUserWithRecoverAccount, - registerUser, - authenticateUser, + registerCredentialWithSignUp, + authenticateCredentialWithSignIn, + registerCredentialWithRecoverAccount, + registerCredential, + authenticateCredential, }; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index f62f0028..40fe27cb 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -354,7 +354,7 @@ export default function getRecipeImplementation( fetchResponse, }; }, - registerUser: async function ({ registrationOptions }) { + registerCredential: async function ({ registrationOptions }) { let registrationResponse: RegistrationResponseJSON; try { registrationResponse = await startRegistration({ optionsJSON: registrationOptions }); @@ -374,7 +374,7 @@ export default function getRecipeImplementation( registrationResponse, }; }, - registerUserWithSignUp: async function ({ email, options, userContext }) { + registerCredentialWithSignUp: async function ({ email, options, userContext }) { // Get the registration options by using the passed email ID. const registrationOptions = await this.getRegisterOptions({ options, userContext, email }); if (registrationOptions?.status !== "OK") { @@ -391,21 +391,21 @@ export default function getRecipeImplementation( } // We should have received a valid registration options response. - const registerUserResponse = await this.registerUser({ registrationOptions }); - if (registerUserResponse.status !== "OK") { - return registerUserResponse; + const registerCredentialResponse = await this.registerCredential({ registrationOptions }); + if (registerCredentialResponse.status !== "OK") { + return registerCredentialResponse; } // We should have a valid registration response for the passed credentials // and we are good to go ahead and verify them. return await this.signUp({ webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registerUserResponse.registrationResponse, + credential: registerCredentialResponse.registrationResponse, options, userContext, }); }, - authenticateUser: async function ({ authenticationOptions }) { + authenticateCredential: async function ({ authenticationOptions }) { let authenticationResponse: AuthenticationResponseJSON; try { authenticationResponse = await startAuthentication({ optionsJSON: authenticationOptions }); @@ -421,7 +421,7 @@ export default function getRecipeImplementation( authenticationResponse: authenticationResponse, }; }, - authenticateUserWithSignIn: async function ({ email, options, userContext }) { + authenticateCredentialWithSignIn: async function ({ email, options, userContext }) { // Make a call to get the sign in options using the entered email ID. const signInOptions = await this.getSignInOptions({ email, options, userContext }); if (signInOptions?.status !== "OK") { @@ -430,21 +430,23 @@ export default function getRecipeImplementation( } // We should have the options ready and are good to start the authentication - const authenticateUserResponse = await this.authenticateUser({ authenticationOptions: signInOptions }); - if (authenticateUserResponse.status !== "OK") { - return authenticateUserResponse; + const authenticateCredentialResponse = await this.authenticateCredential({ + authenticationOptions: signInOptions, + }); + if (authenticateCredentialResponse.status !== "OK") { + return authenticateCredentialResponse; } // We should have a valid authentication response at this point so we can // go ahead and sign in the user. return await this.signIn({ webauthnGeneratedOptionsId: signInOptions.webauthnGeneratedOptionsId, - credential: authenticateUserResponse.authenticationResponse, + credential: authenticateCredentialResponse.authenticationResponse, options: options, userContext: userContext, }); }, - registerUserWithRecoverAccount: async function ({ recoverAccountToken, options, userContext }) { + registerCredentialWithRecoverAccount: async function ({ recoverAccountToken, options, userContext }) { // Get the registration options based on the recoverAccountToken and // register the device against the user. const registrationOptions = await this.getRegisterOptions({ options, userContext, recoverAccountToken }); @@ -462,15 +464,15 @@ export default function getRecipeImplementation( } // We should have received a valid registration options response. - const registerUserResponse = await this.registerUser({ registrationOptions }); - if (registerUserResponse.status !== "OK") { - return registerUserResponse; + const registerCredentialResponse = await this.registerCredential({ registrationOptions }); + if (registerCredentialResponse.status !== "OK") { + return registerCredentialResponse; } return await this.recoverAccount({ token: recoverAccountToken, webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registerUserResponse.registrationResponse, + credential: registerCredentialResponse.registrationResponse, options, userContext, }); diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 5a8ac1ce..75e31694 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -229,7 +229,7 @@ export type RecipeInterface = { | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; - registerUser: (input: { registrationOptions: RegistrationOptions }) => Promise< + registerCredential: (input: { registrationOptions: RegistrationOptions }) => Promise< | { status: "OK"; registrationResponse: RegistrationResponseJSON; @@ -237,14 +237,18 @@ export type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } >; - authenticateUser: (input: { authenticationOptions: AuthenticationOptions }) => Promise< + authenticateCredential: (input: { authenticationOptions: AuthenticationOptions }) => Promise< | { status: "OK"; authenticationResponse: AuthenticationResponseJSON; } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } >; - registerUserWithSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + registerCredentialWithSignUp: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< | { status: "OK"; user: User; @@ -272,7 +276,7 @@ export type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } >; - authenticateUserWithSignIn: (input: { + authenticateCredentialWithSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any; @@ -295,7 +299,7 @@ export type RecipeInterface = { | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } | GeneralErrorResponse >; - registerUserWithRecoverAccount: (input: { + registerCredentialWithRecoverAccount: (input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; From 7d724e2076f5aae99b568aa6179eb11b37a892dd Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Thu, 19 Dec 2024 14:23:27 +0530 Subject: [PATCH 38/46] Add build files and make webauthn exported from root of the package --- lib/build/recipe/webauthn/index.d.ts | 112 ++++++++++-- lib/build/recipe/webauthn/index.js | 90 ++++++---- .../recipe/webauthn/recipeImplementation.js | 170 ++++++++++++------ lib/build/recipe/webauthn/types.d.ts | 143 +++++++++------ lib/ts/recipe/webauthn/index.ts | 2 + recipe/webauthn/index.d.ts | 17 ++ recipe/webauthn/index.js | 20 +++ recipe/webauthn/types/index.d.ts | 17 ++ recipe/webauthn/types/index.js | 20 +++ 9 files changed, 430 insertions(+), 161 deletions(-) create mode 100644 recipe/webauthn/index.d.ts create mode 100644 recipe/webauthn/index.js create mode 100644 recipe/webauthn/types/index.d.ts create mode 100644 recipe/webauthn/types/index.js diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 699b9bc7..76c8f694 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -1,7 +1,15 @@ import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simplewebauthn/browser"; import { GeneralErrorResponse, User } from "../../types"; import { RecipeFunctionOptions } from "../recipeModule/types"; -import { CredentialPayload, ResidentKey, UserInput, UserVerification } from "./types"; +import { + CredentialPayload, + ResidentKey, + UserInput, + UserVerification, + RegistrationOptions, + AuthenticationOptions, + RecipeInterface, +} from "./types"; export default class RecipeWrapper { static init( config?: UserInput @@ -20,7 +28,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) */ - static registerOptions( + static getRegisterOptions( input: { options?: RecipeFunctionOptions; userContext: any; @@ -90,7 +98,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - static signInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getSignInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -194,7 +202,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence */ - static emailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getEmailExists(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; exists: boolean; @@ -271,6 +279,47 @@ export default class RecipeWrapper { reason: string; } >; + /** + * Register credential with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param registrationOptions Options to pass for the registration. + * + * @returns `{ status: "OK", ...}` if successful along with registration response received + */ + static registerCredential(input: { registrationOptions: RegistrationOptions }): Promise< + | { + status: "OK"; + registrationResponse: RegistrationResponseJSON; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } + >; + /** + * Authenticate the credential with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param authenticationOptions Options to pass for the authentication. + * + * @returns `{ status: "OK", ...}` if successful along with authentication response received + */ + static authenticateCredential(input: { authenticationOptions: AuthenticationOptions }): Promise< + | { + status: "OK"; + authenticationResponse: AuthenticationResponseJSON; + } + | { + status: "FAILED_TO_AUTHENTICATE_USER"; + error: any; + } + >; /** * Register the new device and signup the user with the passed email ID. * @@ -284,7 +333,11 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerAndSignUp(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static registerCredentialWithSignUp(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< | { status: "OK"; user: User; @@ -329,6 +382,10 @@ export default class RecipeWrapper { | { status: "AUTHENTICATOR_ALREADY_REGISTERED"; } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } >; /** * Authenticate the user and sign them in after verifying their identity. @@ -343,7 +400,11 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static authenticateAndSignIn(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static authenticateCredentialWithSignIn(input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }): Promise< | { status: "OK"; user: User; @@ -362,6 +423,10 @@ export default class RecipeWrapper { reason: string; fetchResponse: Response; } + | { + status: "FAILED_TO_AUTHENTICATE_USER"; + error: any; + } | GeneralErrorResponse >; /** @@ -377,7 +442,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static registerAndRecoverAccount(input: { + static registerCredentialWithRecoverAccount(input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; @@ -421,29 +486,38 @@ export default class RecipeWrapper { | { status: "AUTHENTICATOR_ALREADY_REGISTERED"; } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } >; } declare const init: typeof RecipeWrapper.init; -declare const registerOptions: typeof RecipeWrapper.registerOptions; -declare const signInOptions: typeof RecipeWrapper.signInOptions; +declare const getRegisterOptions: typeof RecipeWrapper.getRegisterOptions; +declare const getSignInOptions: typeof RecipeWrapper.getSignInOptions; declare const signUp: typeof RecipeWrapper.signUp; declare const signIn: typeof RecipeWrapper.signIn; -declare const emailExists: typeof RecipeWrapper.emailExists; +declare const getEmailExists: typeof RecipeWrapper.getEmailExists; declare const generateRecoverAccountToken: typeof RecipeWrapper.generateRecoverAccountToken; declare const recoverAccount: typeof RecipeWrapper.recoverAccount; -declare const registerAndSignup: typeof RecipeWrapper.registerAndSignUp; -declare const authenticateAndSignIn: typeof RecipeWrapper.authenticateAndSignIn; -declare const registerAndRecoverAccount: typeof RecipeWrapper.registerAndRecoverAccount; +declare const registerCredentialWithSignUp: typeof RecipeWrapper.registerCredentialWithSignUp; +declare const authenticateCredentialWithSignIn: typeof RecipeWrapper.authenticateCredentialWithSignIn; +declare const registerCredentialWithRecoverAccount: typeof RecipeWrapper.registerCredentialWithRecoverAccount; +declare const registerCredential: typeof RecipeWrapper.registerCredential; +declare const authenticateCredential: typeof RecipeWrapper.authenticateCredential; export { init, - registerOptions, - signInOptions, + getRegisterOptions, + getSignInOptions, signUp, signIn, - emailExists, + getEmailExists, generateRecoverAccountToken, recoverAccount, - registerAndSignup, - authenticateAndSignIn, - registerAndRecoverAccount, + registerCredentialWithSignUp, + authenticateCredentialWithSignIn, + registerCredentialWithRecoverAccount, + registerCredential, + authenticateCredential, + RecipeInterface, }; diff --git a/lib/build/recipe/webauthn/index.js b/lib/build/recipe/webauthn/index.js index 727280d8..1fd2eb42 100644 --- a/lib/build/recipe/webauthn/index.js +++ b/lib/build/recipe/webauthn/index.js @@ -28,16 +28,18 @@ var __assign = return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.registerAndRecoverAccount = - exports.authenticateAndSignIn = - exports.registerAndSignup = +exports.authenticateCredential = + exports.registerCredential = + exports.registerCredentialWithRecoverAccount = + exports.authenticateCredentialWithSignIn = + exports.registerCredentialWithSignUp = exports.recoverAccount = exports.generateRecoverAccountToken = - exports.emailExists = + exports.getEmailExists = exports.signIn = exports.signUp = - exports.signInOptions = - exports.registerOptions = + exports.getSignInOptions = + exports.getRegisterOptions = exports.init = void 0; var utils_1 = require("../../utils"); @@ -61,8 +63,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along a description of the created webauthn details (challenge, etc.) */ - RecipeWrapper.registerOptions = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerOptions( + RecipeWrapper.getRegisterOptions = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.getRegisterOptions( __assign(__assign({}, input), { userContext: (0, utils_1.getNormalisedUserContext)( input === null || input === void 0 ? void 0 : input.userContext @@ -82,8 +84,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - RecipeWrapper.signInOptions = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.signInOptions( + RecipeWrapper.getSignInOptions = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.getSignInOptions( __assign(__assign({}, input), { userContext: (0, utils_1.getNormalisedUserContext)( input === null || input === void 0 ? void 0 : input.userContext @@ -143,8 +145,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along with a boolean indicating existence */ - RecipeWrapper.emailExists = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.emailExists( + RecipeWrapper.getEmailExists = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.getEmailExists( __assign(__assign({}, input), { userContext: input === null || input === void 0 ? void 0 : input.userContext, }) @@ -190,6 +192,30 @@ var RecipeWrapper = /** @class */ (function () { }) ); }; + /** + * Register credential with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param registrationOptions Options to pass for the registration. + * + * @returns `{ status: "OK", ...}` if successful along with registration response received + */ + RecipeWrapper.registerCredential = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerCredential(input); + }; + /** + * Authenticate the credential with the passed options by using native webauthn functions. + * + * It uses `@simplewebauthn/browser` to make the webauthn calls. + * + * @param authenticationOptions Options to pass for the authentication. + * + * @returns `{ status: "OK", ...}` if successful along with authentication response received + */ + RecipeWrapper.authenticateCredential = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.authenticateCredential(input); + }; /** * Register the new device and signup the user with the passed email ID. * @@ -203,8 +229,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - RecipeWrapper.registerAndSignUp = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerAndSignUp( + RecipeWrapper.registerCredentialWithSignUp = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerCredentialWithSignUp( __assign(__assign({}, input), { userContext: input === null || input === void 0 ? void 0 : input.userContext, }) @@ -223,8 +249,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - RecipeWrapper.authenticateAndSignIn = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.authenticateAndSignIn( + RecipeWrapper.authenticateCredentialWithSignIn = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.authenticateCredentialWithSignIn( __assign(__assign({}, input), { userContext: input === null || input === void 0 ? void 0 : input.userContext, }) @@ -243,8 +269,8 @@ var RecipeWrapper = /** @class */ (function () { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - RecipeWrapper.registerAndRecoverAccount = function (input) { - return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerAndRecoverAccount( + RecipeWrapper.registerCredentialWithRecoverAccount = function (input) { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.registerCredentialWithRecoverAccount( __assign(__assign({}, input), { userContext: input === null || input === void 0 ? void 0 : input.userContext, }) @@ -255,23 +281,27 @@ var RecipeWrapper = /** @class */ (function () { exports.default = RecipeWrapper; var init = RecipeWrapper.init; exports.init = init; -var registerOptions = RecipeWrapper.registerOptions; -exports.registerOptions = registerOptions; -var signInOptions = RecipeWrapper.signInOptions; -exports.signInOptions = signInOptions; +var getRegisterOptions = RecipeWrapper.getRegisterOptions; +exports.getRegisterOptions = getRegisterOptions; +var getSignInOptions = RecipeWrapper.getSignInOptions; +exports.getSignInOptions = getSignInOptions; var signUp = RecipeWrapper.signUp; exports.signUp = signUp; var signIn = RecipeWrapper.signIn; exports.signIn = signIn; -var emailExists = RecipeWrapper.emailExists; -exports.emailExists = emailExists; +var getEmailExists = RecipeWrapper.getEmailExists; +exports.getEmailExists = getEmailExists; var generateRecoverAccountToken = RecipeWrapper.generateRecoverAccountToken; exports.generateRecoverAccountToken = generateRecoverAccountToken; var recoverAccount = RecipeWrapper.recoverAccount; exports.recoverAccount = recoverAccount; -var registerAndSignup = RecipeWrapper.registerAndSignUp; -exports.registerAndSignup = registerAndSignup; -var authenticateAndSignIn = RecipeWrapper.authenticateAndSignIn; -exports.authenticateAndSignIn = authenticateAndSignIn; -var registerAndRecoverAccount = RecipeWrapper.registerAndRecoverAccount; -exports.registerAndRecoverAccount = registerAndRecoverAccount; +var registerCredentialWithSignUp = RecipeWrapper.registerCredentialWithSignUp; +exports.registerCredentialWithSignUp = registerCredentialWithSignUp; +var authenticateCredentialWithSignIn = RecipeWrapper.authenticateCredentialWithSignIn; +exports.authenticateCredentialWithSignIn = authenticateCredentialWithSignIn; +var registerCredentialWithRecoverAccount = RecipeWrapper.registerCredentialWithRecoverAccount; +exports.registerCredentialWithRecoverAccount = registerCredentialWithRecoverAccount; +var registerCredential = RecipeWrapper.registerCredential; +exports.registerCredential = registerCredential; +var authenticateCredential = RecipeWrapper.authenticateCredential; +exports.authenticateCredential = authenticateCredential; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js index 1e55a097..84fb5ca2 100644 --- a/lib/build/recipe/webauthn/recipeImplementation.js +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -166,7 +166,7 @@ var browser_1 = require("@simplewebauthn/browser"); function getRecipeImplementation(recipeImplInput) { var querier = new querier_1.default(recipeImplInput.recipeId, recipeImplInput.appInfo); return { - registerOptions: function (_a) { + getRegisterOptions: function (_a) { var options = _a.options, userContext = _a.userContext, email = _a.email, @@ -215,7 +215,7 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, - signInOptions: function (_a) { + getSignInOptions: function (_a) { var email = _a.email, options = _a.options, userContext = _a.userContext; @@ -360,7 +360,7 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, - emailExists: function (_a) { + getEmailExists: function (_a) { var email = _a.email, options = _a.options, userContext = _a.userContext; @@ -502,18 +502,57 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, - registerAndSignUp: function (_a) { + registerCredential: function (_a) { + var registrationOptions = _a.registrationOptions; + return __awaiter(this, void 0, void 0, function () { + var registrationResponse, error_1; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 2, , 3]); + return [ + 4 /*yield*/, + (0, browser_1.startRegistration)({ optionsJSON: registrationOptions }), + ]; + case 1: + registrationResponse = _b.sent(); + return [3 /*break*/, 3]; + case 2: + error_1 = _b.sent(); + if (error_1.name === "InvalidStateError") { + return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; + } + return [ + 2 /*return*/, + { + status: "FAILED_TO_REGISTER_USER", + error: error_1, + }, + ]; + case 3: + return [ + 2 /*return*/, + { + status: "OK", + registrationResponse: registrationResponse, + }, + ]; + } + }); + }); + }, + registerCredentialWithSignUp: function (_a) { var email = _a.email, options = _a.options, userContext = _a.userContext; return __awaiter(this, void 0, void 0, function () { - var registrationOptions, registrationResponse, error_1; + var registrationOptions, registerCredentialResponse; return __generator(this, function (_b) { switch (_b.label) { case 0: return [ 4 /*yield*/, - this.registerOptions({ options: options, userContext: userContext, email: email }), + this.getRegisterOptions({ options: options, userContext: userContext, email: email }), ]; case 1: registrationOptions = _b.sent(); @@ -537,33 +576,22 @@ function getRecipeImplementation(recipeImplInput) { } return [2 /*return*/, registrationOptions]; } - _b.label = 2; + return [4 /*yield*/, this.registerCredential({ registrationOptions: registrationOptions })]; case 2: - _b.trys.push([2, 4, , 5]); - return [ - 4 /*yield*/, - (0, browser_1.startRegistration)({ optionsJSON: registrationOptions }), - ]; - case 3: - registrationResponse = _b.sent(); - return [3 /*break*/, 5]; - case 4: - error_1 = _b.sent(); - if (error_1.name === "InvalidStateError") { - return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; + registerCredentialResponse = _b.sent(); + if (registerCredentialResponse.status !== "OK") { + return [2 /*return*/, registerCredentialResponse]; } - throw error_1; - case 5: return [ 4 /*yield*/, this.signUp({ webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registrationResponse, + credential: registerCredentialResponse.registrationResponse, options: options, userContext: userContext, }), ]; - case 6: + case 3: // We should have a valid registration response for the passed credentials // and we are good to go ahead and verify them. return [2 /*return*/, _b.sent()]; @@ -571,18 +599,54 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, - authenticateAndSignIn: function (_a) { + authenticateCredential: function (_a) { + var authenticationOptions = _a.authenticationOptions; + return __awaiter(this, void 0, void 0, function () { + var authenticationResponse, error_2; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _b.trys.push([0, 2, , 3]); + return [ + 4 /*yield*/, + (0, browser_1.startAuthentication)({ optionsJSON: authenticationOptions }), + ]; + case 1: + authenticationResponse = _b.sent(); + return [3 /*break*/, 3]; + case 2: + error_2 = _b.sent(); + return [ + 2 /*return*/, + { + status: "FAILED_TO_AUTHENTICATE_USER", + error: error_2, + }, + ]; + case 3: + return [ + 2 /*return*/, + { + status: "OK", + authenticationResponse: authenticationResponse, + }, + ]; + } + }); + }); + }, + authenticateCredentialWithSignIn: function (_a) { var email = _a.email, options = _a.options, userContext = _a.userContext; return __awaiter(this, void 0, void 0, function () { - var signInOptions, authenticationResponse, error_2; + var signInOptions, authenticateCredentialResponse; return __generator(this, function (_b) { switch (_b.label) { case 0: return [ 4 /*yield*/, - this.signInOptions({ email: email, options: options, userContext: userContext }), + this.getSignInOptions({ email: email, options: options, userContext: userContext }), ]; case 1: signInOptions = _b.sent(); @@ -593,28 +657,27 @@ function getRecipeImplementation(recipeImplInput) { // We want to return the error as is if status was not "OK" return [2 /*return*/, signInOptions]; } - _b.label = 2; + return [ + 4 /*yield*/, + this.authenticateCredential({ + authenticationOptions: signInOptions, + }), + ]; case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, (0, browser_1.startAuthentication)({ optionsJSON: signInOptions })]; - case 3: - authenticationResponse = _b.sent(); - return [3 /*break*/, 5]; - case 4: - error_2 = _b.sent(); - // TODO: Do we need to do something with the error besides throwing it? - throw error_2; - case 5: + authenticateCredentialResponse = _b.sent(); + if (authenticateCredentialResponse.status !== "OK") { + return [2 /*return*/, authenticateCredentialResponse]; + } return [ 4 /*yield*/, this.signIn({ webauthnGeneratedOptionsId: signInOptions.webauthnGeneratedOptionsId, - credential: authenticationResponse, + credential: authenticateCredentialResponse.authenticationResponse, options: options, userContext: userContext, }), ]; - case 6: + case 3: // We should have a valid authentication response at this point so we can // go ahead and sign in the user. return [2 /*return*/, _b.sent()]; @@ -622,18 +685,18 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, - registerAndRecoverAccount: function (_a) { + registerCredentialWithRecoverAccount: function (_a) { var recoverAccountToken = _a.recoverAccountToken, options = _a.options, userContext = _a.userContext; return __awaiter(this, void 0, void 0, function () { - var registrationOptions, registrationResponse, error_3; + var registrationOptions, registerCredentialResponse; return __generator(this, function (_b) { switch (_b.label) { case 0: return [ 4 /*yield*/, - this.registerOptions({ + this.getRegisterOptions({ options: options, userContext: userContext, recoverAccountToken: recoverAccountToken, @@ -659,34 +722,23 @@ function getRecipeImplementation(recipeImplInput) { } return [2 /*return*/, registrationOptions]; } - _b.label = 2; + return [4 /*yield*/, this.registerCredential({ registrationOptions: registrationOptions })]; case 2: - _b.trys.push([2, 4, , 5]); - return [ - 4 /*yield*/, - (0, browser_1.startRegistration)({ optionsJSON: registrationOptions }), - ]; - case 3: - registrationResponse = _b.sent(); - return [3 /*break*/, 5]; - case 4: - error_3 = _b.sent(); - if (error_3.name === "InvalidStateError") { - return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; + registerCredentialResponse = _b.sent(); + if (registerCredentialResponse.status !== "OK") { + return [2 /*return*/, registerCredentialResponse]; } - throw error_3; - case 5: return [ 4 /*yield*/, this.recoverAccount({ token: recoverAccountToken, webauthnGeneratedOptionsId: registrationOptions.webauthnGeneratedOptionsId, - credential: registrationResponse, + credential: registerCredentialResponse.registrationResponse, options: options, userContext: userContext, }), ]; - case 6: + case 3: return [2 /*return*/, _b.sent()]; } }); diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index fd7a0986..154bcd82 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -53,8 +53,47 @@ export declare type CredentialPayload = { clientExtensionResults: any; type: "public-key"; }; +export declare type RegistrationOptions = { + status: "OK"; + webauthnGeneratedOptionsId: string; + rp: { + id: string; + name: string; + }; + user: { + id: string; + name: string; + displayName: string; + }; + challenge: string; + timeout: number; + excludeCredentials: { + id: string; + type: "public-key"; + transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; + }[]; + attestation: "none" | "indirect" | "direct" | "enterprise"; + pubKeyCredParams: { + alg: number; + type: "public-key"; + }[]; + authenticatorSelection: { + requireResidentKey: boolean; + residentKey: ResidentKey; + userVerification: UserVerification; + }; + fetchResponse: Response; +}; +export declare type AuthenticationOptions = { + status: "OK"; + webauthnGeneratedOptionsId: string; + challenge: string; + timeout: number; + userVerification: UserVerification; + fetchResponse: Response; +}; export declare type RecipeInterface = { - registerOptions: ( + getRegisterOptions: ( input: { options?: RecipeFunctionOptions; userContext: any; @@ -67,37 +106,7 @@ export declare type RecipeInterface = { } ) ) => Promise< - | { - status: "OK"; - webauthnGeneratedOptionsId: string; - rp: { - id: string; - name: string; - }; - user: { - id: string; - name: string; - displayName: string; - }; - challenge: string; - timeout: number; - excludeCredentials: { - id: string; - type: "public-key"; - transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb")[]; - }[]; - attestation: "none" | "indirect" | "direct" | "enterprise"; - pubKeyCredParams: { - alg: number; - type: "public-key"; - }[]; - authenticatorSelection: { - requireResidentKey: boolean; - residentKey: ResidentKey; - userVerification: UserVerification; - }; - fetchResponse: Response; - } + | RegistrationOptions | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response; @@ -112,15 +121,8 @@ export declare type RecipeInterface = { fetchResponse: Response; } >; - signInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< - | { - status: "OK"; - webauthnGeneratedOptionsId: string; - challenge: string; - timeout: number; - userVerification: UserVerification; - fetchResponse: Response; - } + getSignInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + | AuthenticationOptions | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response; @@ -188,7 +190,7 @@ export declare type RecipeInterface = { } | GeneralErrorResponse >; - emailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + getEmailExists: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; exists: boolean; @@ -248,7 +250,34 @@ export declare type RecipeInterface = { fetchResponse: Response; } >; - registerAndSignUp: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + registerCredential: (input: { registrationOptions: RegistrationOptions }) => Promise< + | { + status: "OK"; + registrationResponse: RegistrationResponseJSON; + } + | { + status: "AUTHENTICATOR_ALREADY_REGISTERED"; + } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } + >; + authenticateCredential: (input: { authenticationOptions: AuthenticationOptions }) => Promise< + | { + status: "OK"; + authenticationResponse: AuthenticationResponseJSON; + } + | { + status: "FAILED_TO_AUTHENTICATE_USER"; + error: any; + } + >; + registerCredentialWithSignUp: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< | { status: "OK"; user: User; @@ -277,10 +306,6 @@ export declare type RecipeInterface = { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } - | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; - fetchResponse: Response; - } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; @@ -293,8 +318,16 @@ export declare type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED"; } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } >; - authenticateAndSignIn: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + authenticateCredentialWithSignIn: (input: { + email: string; + options?: RecipeFunctionOptions; + userContext: any; + }) => Promise< | { status: "OK"; user: User; @@ -313,9 +346,13 @@ export declare type RecipeInterface = { reason: string; fetchResponse: Response; } + | { + status: "FAILED_TO_AUTHENTICATE_USER"; + error: any; + } | GeneralErrorResponse >; - registerAndRecoverAccount: (input: { + registerCredentialWithRecoverAccount: (input: { recoverAccountToken: string; options?: RecipeFunctionOptions; userContext: any; @@ -347,10 +384,6 @@ export declare type RecipeInterface = { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } - | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; - fetchResponse: Response; - } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; @@ -359,5 +392,9 @@ export declare type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED"; } + | { + status: "FAILED_TO_REGISTER_USER"; + error: any; + } >; }; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index d943f20c..c19e6c73 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -25,6 +25,7 @@ import { UserVerification, RegistrationOptions, AuthenticationOptions, + RecipeInterface, } from "./types"; export default class RecipeWrapper { @@ -514,4 +515,5 @@ export { registerCredentialWithRecoverAccount, registerCredential, authenticateCredential, + RecipeInterface, }; diff --git a/recipe/webauthn/index.d.ts b/recipe/webauthn/index.d.ts new file mode 100644 index 00000000..8548eac8 --- /dev/null +++ b/recipe/webauthn/index.d.ts @@ -0,0 +1,17 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +export * from "../../lib/build/recipe/webauthn"; +import * as _default from "../../lib/build/recipe/webauthn"; +export default _default; diff --git a/recipe/webauthn/index.js b/recipe/webauthn/index.js new file mode 100644 index 00000000..eca8f159 --- /dev/null +++ b/recipe/webauthn/index.js @@ -0,0 +1,20 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +exports.__esModule = true; +__export(require("../../lib/build/recipe/webauthn")); diff --git a/recipe/webauthn/types/index.d.ts b/recipe/webauthn/types/index.d.ts new file mode 100644 index 00000000..9c765ab7 --- /dev/null +++ b/recipe/webauthn/types/index.d.ts @@ -0,0 +1,17 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +export * from "../../../lib/build/recipe/webauthn/types"; +import * as _default from "../../../lib/build/recipe/webauthn/types"; +export default _default; diff --git a/recipe/webauthn/types/index.js b/recipe/webauthn/types/index.js new file mode 100644 index 00000000..85502879 --- /dev/null +++ b/recipe/webauthn/types/index.js @@ -0,0 +1,20 @@ +/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +exports.__esModule = true; +__export(require("../../../lib/build/recipe/webauthn/types")); From 06c468f4652bbcb29c18aa0b49d6af0a6c73ef13 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 23 Dec 2024 10:26:50 +0530 Subject: [PATCH 39/46] Add a type fix for signUp function not returning fetchResponse in type def --- lib/ts/recipe/webauthn/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index c19e6c73..34508153 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -160,17 +160,19 @@ export default class RecipeWrapper { | { status: "OK"; user: User; + fetchResponse: Response; } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } - | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } - | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } - | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } + | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } > { return Recipe.getInstanceOrThrow().recipeImplementation.signUp({ ...input, From f504ad30c40d52ba88bbe08616cae8373b62cd96 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 23 Dec 2024 13:17:29 +0530 Subject: [PATCH 40/46] Add type fix for some other methods defined for webauthn --- lib/build/recipe/webauthn/index.d.ts | 7 +++++++ lib/ts/recipe/webauthn/index.ts | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 76c8f694..15464d00 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -136,27 +136,34 @@ export default class RecipeWrapper { | { status: "OK"; user: User; + fetchResponse: Response; } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; } | { status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; + fetchResponse: Response; } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; + fetchResponse: Response; } >; /** diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 34508153..20e36f5e 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -202,11 +202,13 @@ export default class RecipeWrapper { | { status: "OK"; user: User; + fetchResponse: Response; } - | { status: "INVALID_CREDENTIALS_ERROR" } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse > { @@ -231,6 +233,7 @@ export default class RecipeWrapper { | { status: "OK"; exists: boolean; + fetchResponse: Response; } | GeneralErrorResponse > { @@ -258,8 +261,9 @@ export default class RecipeWrapper { }): Promise< | { status: "OK"; + fetchResponse: Response; } - | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string } + | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string; fetchResponse: Response } | GeneralErrorResponse > { return Recipe.getInstanceOrThrow().recipeImplementation.generateRecoverAccountToken({ @@ -294,13 +298,14 @@ export default class RecipeWrapper { status: "OK"; user: User; email: string; + fetchResponse: Response; } | GeneralErrorResponse - | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } - | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } - | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } + | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } + | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } + | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } > { return Recipe.getInstanceOrThrow().recipeImplementation.recoverAccount({ ...input, From 052ae4899fd5a7d9518e2a002db06bbebfe9b7d0 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 20 Jan 2025 13:07:23 +0530 Subject: [PATCH 41/46] Add support for parsing and using expiresAt and createdAt fields --- lib/build/recipe/webauthn/index.d.ts | 14 ++++++++++++++ lib/build/recipe/webauthn/types.d.ts | 2 ++ lib/ts/recipe/webauthn/index.ts | 2 ++ lib/ts/recipe/webauthn/recipeImplementation.ts | 2 ++ lib/ts/recipe/webauthn/types.ts | 2 ++ 5 files changed, 22 insertions(+) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 15464d00..080ffebc 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -44,6 +44,8 @@ export default class RecipeWrapper { | { status: "OK"; webauthnGeneratedOptionsId: string; + createdAt: string; + expiresAt: string; rp: { id: string; name: string; @@ -188,13 +190,16 @@ export default class RecipeWrapper { | { status: "OK"; user: User; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -213,6 +218,7 @@ export default class RecipeWrapper { | { status: "OK"; exists: boolean; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -234,10 +240,12 @@ export default class RecipeWrapper { }): Promise< | { status: "OK"; + fetchResponse: Response; } | { status: "RECOVER_ACCOUNT_NOT_ALLOWED"; reason: string; + fetchResponse: Response; } | GeneralErrorResponse >; @@ -267,23 +275,29 @@ export default class RecipeWrapper { status: "OK"; user: User; email: string; + fetchResponse: Response; } | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; + fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; + fetchResponse: Response; } | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; } | { status: "INVALID_GENERATED_OPTIONS_ERROR"; + fetchResponse: Response; } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; + fetchResponse: Response; } >; /** diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index 154bcd82..8c478b47 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -56,6 +56,8 @@ export declare type CredentialPayload = { export declare type RegistrationOptions = { status: "OK"; webauthnGeneratedOptionsId: string; + createdAt: string; + expiresAt: string; rp: { id: string; name: string; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 20e36f5e..51fd0603 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -56,6 +56,8 @@ export default class RecipeWrapper { | { status: "OK"; webauthnGeneratedOptionsId: string; + createdAt: string; + expiresAt: string; rp: { id: string; name: string; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 40fe27cb..7c48eb72 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -45,6 +45,8 @@ export default function getRecipeImplementation( | { status: "OK"; webauthnGeneratedOptionsId: string; + createdAt: string; + expiresAt: string; rp: { id: string; name: string; diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 75e31694..941cb1a3 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -79,6 +79,8 @@ export type CredentialPayload = { export type RegistrationOptions = { status: "OK"; webauthnGeneratedOptionsId: string; + createdAt: string; + expiresAt: string; rp: { id: string; name: string; From 96d644a1928eae7a5a559dd050503db1172e1c2f Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 27 Jan 2025 12:24:29 +0530 Subject: [PATCH 42/46] Add support for not requiring email for sign in --- lib/build/recipe/webauthn/index.d.ts | 8 ++------ lib/build/recipe/webauthn/recipeImplementation.js | 15 ++++----------- lib/build/recipe/webauthn/types.d.ts | 8 ++------ lib/ts/recipe/webauthn/index.ts | 8 ++------ lib/ts/recipe/webauthn/recipeImplementation.ts | 10 ++++------ lib/ts/recipe/webauthn/types.ts | 8 ++------ 6 files changed, 16 insertions(+), 41 deletions(-) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 080ffebc..1a650080 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -100,7 +100,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - static getSignInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getSignInOptions(input: { options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -421,11 +421,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static authenticateCredentialWithSignIn(input: { - email: string; - options?: RecipeFunctionOptions; - userContext: any; - }): Promise< + static authenticateCredentialWithSignIn(input: { options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; user: User; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js index 84fb5ca2..3c514819 100644 --- a/lib/build/recipe/webauthn/recipeImplementation.js +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -216,8 +216,7 @@ function getRecipeImplementation(recipeImplInput) { }); }, getSignInOptions: function (_a) { - var email = _a.email, - options = _a.options, + var options = _a.options, userContext = _a.userContext; return __awaiter(this, void 0, void 0, function () { var _b, jsonBody, fetchResponse, _c, _d; @@ -238,9 +237,7 @@ function getRecipeImplementation(recipeImplInput) { _e.sent(), "/webauthn/options/signin", { - body: JSON.stringify({ - email: email, - }), + body: JSON.stringify({}), }, querier_1.default.preparePreAPIHook({ recipePreAPIHook: recipeImplInput.preAPIHook, @@ -636,18 +633,14 @@ function getRecipeImplementation(recipeImplInput) { }); }, authenticateCredentialWithSignIn: function (_a) { - var email = _a.email, - options = _a.options, + var options = _a.options, userContext = _a.userContext; return __awaiter(this, void 0, void 0, function () { var signInOptions, authenticateCredentialResponse; return __generator(this, function (_b) { switch (_b.label) { case 0: - return [ - 4 /*yield*/, - this.getSignInOptions({ email: email, options: options, userContext: userContext }), - ]; + return [4 /*yield*/, this.getSignInOptions({ options: options, userContext: userContext })]; case 1: signInOptions = _b.sent(); if ( diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index 8c478b47..767a7005 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -123,7 +123,7 @@ export declare type RecipeInterface = { fetchResponse: Response; } >; - getSignInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + getSignInOptions: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | AuthenticationOptions | { status: "INVALID_GENERATED_OPTIONS_ERROR"; @@ -325,11 +325,7 @@ export declare type RecipeInterface = { error: any; } >; - authenticateCredentialWithSignIn: (input: { - email: string; - options?: RecipeFunctionOptions; - userContext: any; - }) => Promise< + authenticateCredentialWithSignIn: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; user: User; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 51fd0603..b2b9173a 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -118,7 +118,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the webauthn options (challenge, etc.) */ - static getSignInOptions(input: { email: string; options?: RecipeFunctionOptions; userContext: any }): Promise< + static getSignInOptions(input: { options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; webauthnGeneratedOptionsId: string; @@ -419,11 +419,7 @@ export default class RecipeWrapper { * * @returns `{ status: "OK", ...}` if successful along a description of the user details (id, etc.) and email */ - static authenticateCredentialWithSignIn(input: { - email: string; - options?: RecipeFunctionOptions; - userContext: any; - }): Promise< + static authenticateCredentialWithSignIn(input: { options?: RecipeFunctionOptions; userContext: any }): Promise< | { status: "OK"; user: User; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index 7c48eb72..a7c3bdf7 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -117,7 +117,7 @@ export default function getRecipeImplementation( fetchResponse, }; }, - getSignInOptions: async function ({ email, options, userContext }) { + getSignInOptions: async function ({ options, userContext }) { const { jsonBody, fetchResponse } = await querier.post< | { status: "OK"; @@ -138,9 +138,7 @@ export default function getRecipeImplementation( }), "/webauthn/options/signin", { - body: JSON.stringify({ - email, - }), + body: JSON.stringify({}), }, Querier.preparePreAPIHook({ recipePreAPIHook: recipeImplInput.preAPIHook, @@ -423,9 +421,9 @@ export default function getRecipeImplementation( authenticationResponse: authenticationResponse, }; }, - authenticateCredentialWithSignIn: async function ({ email, options, userContext }) { + authenticateCredentialWithSignIn: async function ({ options, userContext }) { // Make a call to get the sign in options using the entered email ID. - const signInOptions = await this.getSignInOptions({ email, options, userContext }); + const signInOptions = await this.getSignInOptions({ options, userContext }); if (signInOptions?.status !== "OK") { // We want to return the error as is if status was not "OK" return signInOptions; diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index 941cb1a3..e36c00fd 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -141,7 +141,7 @@ export type RecipeInterface = { fetchResponse: Response; } >; - getSignInOptions: (input: { email: string; options?: RecipeFunctionOptions; userContext: any }) => Promise< + getSignInOptions: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | AuthenticationOptions | { status: "INVALID_GENERATED_OPTIONS_ERROR"; @@ -278,11 +278,7 @@ export type RecipeInterface = { | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } >; - authenticateCredentialWithSignIn: (input: { - email: string; - options?: RecipeFunctionOptions; - userContext: any; - }) => Promise< + authenticateCredentialWithSignIn: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | { status: "OK"; user: User; From fb49a39cbc8d41f20731096a7a12a1d300acb2bf Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 5 Feb 2025 14:57:07 +0530 Subject: [PATCH 43/46] Fix the type of credential in recoverAccount type definition --- lib/build/recipe/webauthn/index.d.ts | 3 +-- lib/ts/recipe/webauthn/index.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 1a650080..e6422e5b 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -2,7 +2,6 @@ import { AuthenticationResponseJSON, RegistrationResponseJSON } from "@simpleweb import { GeneralErrorResponse, User } from "../../types"; import { RecipeFunctionOptions } from "../recipeModule/types"; import { - CredentialPayload, ResidentKey, UserInput, UserVerification, @@ -267,7 +266,7 @@ export default class RecipeWrapper { static recoverAccount(input: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index b2b9173a..47557677 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -19,7 +19,6 @@ import { getNormalisedUserContext } from "../../utils"; import { RecipeFunctionOptions } from "../recipeModule/types"; import Recipe from "./recipe"; import { - CredentialPayload, ResidentKey, UserInput, UserVerification, @@ -292,7 +291,7 @@ export default class RecipeWrapper { static recoverAccount(input: { token: string; webauthnGeneratedOptionsId: string; - credential: CredentialPayload; + credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; userContext: any; }): Promise< From 98ece8ceacd8473c5e561e04e163bc4d19053a56 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 17 Feb 2025 12:34:45 +0530 Subject: [PATCH 44/46] Update errors received from node SDK regarding webauthn --- lib/build/recipe/webauthn/index.d.ts | 22 ++++++------ lib/build/recipe/webauthn/types.d.ts | 28 +++++++-------- lib/ts/recipe/webauthn/index.ts | 22 ++++++------ .../recipe/webauthn/recipeImplementation.ts | 12 +++---- lib/ts/recipe/webauthn/types.ts | 34 +++++++------------ 5 files changed, 54 insertions(+), 64 deletions(-) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index e6422e5b..aed8005f 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -83,7 +83,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } >; @@ -109,7 +109,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -150,11 +150,11 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -286,11 +286,11 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -383,11 +383,11 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -427,7 +427,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -487,11 +487,11 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index 767a7005..82700cf5 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -119,14 +119,14 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } >; getSignInOptions: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | AuthenticationOptions | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -153,11 +153,11 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -239,11 +239,11 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -290,10 +290,6 @@ export declare type RecipeInterface = { err: string; fetchResponse: Response; } - | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; - fetchResponse: Response; - } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; @@ -305,7 +301,11 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; + fetchResponse: Response; + } + | { + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -332,7 +332,7 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { @@ -366,7 +366,7 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -379,7 +379,7 @@ export declare type RecipeInterface = { fetchResponse: Response; } | { - status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; + status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response; } | { diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 47557677..c1ef3f8e 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -95,7 +95,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } > { @@ -127,7 +127,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -170,8 +170,8 @@ export default class RecipeWrapper { fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } > { @@ -304,8 +304,8 @@ export default class RecipeWrapper { | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } > { return Recipe.getInstanceOrThrow().recipeImplementation.recoverAccount({ @@ -392,8 +392,8 @@ export default class RecipeWrapper { fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } @@ -425,7 +425,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } @@ -478,8 +478,8 @@ export default class RecipeWrapper { | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index a7c3bdf7..d6fa7cb2 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -85,7 +85,7 @@ export default function getRecipeImplementation( fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } >( @@ -128,7 +128,7 @@ export default function getRecipeImplementation( fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -170,8 +170,8 @@ export default function getRecipeImplementation( reason: string; } | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_OPTIONS_ERROR" } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } | { status: "EMAIL_ALREADY_EXISTS_ERROR" } >( @@ -321,8 +321,8 @@ export default function getRecipeImplementation( | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR" } | { status: "INVALID_CREDENTIALS_ERROR" } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR" } - | { status: "INVALID_GENERATED_OPTIONS_ERROR" } + | { status: "OPTIONS_NOT_FOUND_ERROR" } + | { status: "INVALID_OPTIONS_ERROR" } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string } >( await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index e36c00fd..a2d4c5ae 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -137,14 +137,14 @@ export type RecipeInterface = { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } >; getSignInOptions: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | AuthenticationOptions | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse @@ -167,8 +167,8 @@ export type RecipeInterface = { fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } >; @@ -227,8 +227,8 @@ export type RecipeInterface = { | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } - | { status: "INVALID_GENERATED_OPTIONS_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } >; registerCredential: (input: { registrationOptions: RegistrationOptions }) => Promise< @@ -261,10 +261,6 @@ export type RecipeInterface = { err: string; fetchResponse: Response; } - | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; - fetchResponse: Response; - } | GeneralErrorResponse | { status: "SIGN_UP_NOT_ALLOWED"; @@ -272,7 +268,8 @@ export type RecipeInterface = { fetchResponse: Response; } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } @@ -284,16 +281,9 @@ export type RecipeInterface = { user: User; fetchResponse: Response; } - | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; - fetchResponse: Response; - } + | { status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { - status: "SIGN_IN_NOT_ALLOWED"; - reason: string; - fetchResponse: Response; - } + | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; fetchResponse: Response } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } | GeneralErrorResponse >; @@ -313,13 +303,13 @@ export type RecipeInterface = { fetchResponse: Response; } | { - status: "INVALID_GENERATED_OPTIONS_ERROR"; + status: "INVALID_OPTIONS_ERROR"; fetchResponse: Response; } | GeneralErrorResponse | { status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; fetchResponse: Response } | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } - | { status: "GENERATED_OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } + | { status: "OPTIONS_NOT_FOUND_ERROR"; fetchResponse: Response } | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } From 94536f6f3548045148bdea159b8874dd56f718e2 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Wed, 19 Feb 2025 10:13:00 +0530 Subject: [PATCH 45/46] Add support for webauthn not supported error --- lib/build/recipe/webauthn/index.d.ts | 20 +++++++++++++++++++ .../recipe/webauthn/recipeImplementation.js | 12 +++++++++++ lib/build/recipe/webauthn/types.d.ts | 20 +++++++++++++++++++ lib/ts/recipe/webauthn/index.ts | 5 +++++ .../recipe/webauthn/recipeImplementation.ts | 14 +++++++++++++ lib/ts/recipe/webauthn/types.ts | 5 +++++ 6 files changed, 76 insertions(+) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index aed8005f..2a3a89c3 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -320,6 +320,10 @@ export default class RecipeWrapper { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; /** * Authenticate the credential with the passed options by using native webauthn functions. @@ -339,6 +343,10 @@ export default class RecipeWrapper { status: "FAILED_TO_AUTHENTICATE_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; /** * Register the new device and signup the user with the passed email ID. @@ -406,6 +414,10 @@ export default class RecipeWrapper { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; /** * Authenticate the user and sign them in after verifying their identity. @@ -443,6 +455,10 @@ export default class RecipeWrapper { status: "FAILED_TO_AUTHENTICATE_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } | GeneralErrorResponse >; /** @@ -506,6 +522,10 @@ export default class RecipeWrapper { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; } declare const init: typeof RecipeWrapper.init; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js index 3c514819..f4625f05 100644 --- a/lib/build/recipe/webauthn/recipeImplementation.js +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -519,6 +519,12 @@ function getRecipeImplementation(recipeImplInput) { if (error_1.name === "InvalidStateError") { return [2 /*return*/, { status: "AUTHENTICATOR_ALREADY_REGISTERED" }]; } + if ( + error_1.name === "NotSupportedError" || + error_1.message === "WebAuthn is not supported in this browser" + ) { + return [2 /*return*/, { status: "WEBAUTHN_NOT_SUPPORTED", error: error_1 }]; + } return [ 2 /*return*/, { @@ -613,6 +619,12 @@ function getRecipeImplementation(recipeImplInput) { return [3 /*break*/, 3]; case 2: error_2 = _b.sent(); + if ( + error_2.name === "NotSupportedError" || + error_2.message === "WebAuthn is not supported in this browser" + ) { + return [2 /*return*/, { status: "WEBAUTHN_NOT_SUPPORTED", error: error_2 }]; + } return [ 2 /*return*/, { diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index 82700cf5..a6e8d74e 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -264,6 +264,10 @@ export declare type RecipeInterface = { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; authenticateCredential: (input: { authenticationOptions: AuthenticationOptions }) => Promise< | { @@ -274,6 +278,10 @@ export declare type RecipeInterface = { status: "FAILED_TO_AUTHENTICATE_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; registerCredentialWithSignUp: (input: { email: string; @@ -324,6 +332,10 @@ export declare type RecipeInterface = { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; authenticateCredentialWithSignIn: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | { @@ -348,6 +360,10 @@ export declare type RecipeInterface = { status: "FAILED_TO_AUTHENTICATE_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } | GeneralErrorResponse >; registerCredentialWithRecoverAccount: (input: { @@ -394,5 +410,9 @@ export declare type RecipeInterface = { status: "FAILED_TO_REGISTER_USER"; error: any; } + | { + status: "WEBAUTHN_NOT_SUPPORTED"; + error: any; + } >; }; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index c1ef3f8e..3705b7d3 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -330,6 +330,7 @@ export default class RecipeWrapper { } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.registerCredential(input); } @@ -349,6 +350,7 @@ export default class RecipeWrapper { authenticationResponse: AuthenticationResponseJSON; } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.authenticateCredential(input); } @@ -398,6 +400,7 @@ export default class RecipeWrapper { | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.registerCredentialWithSignUp({ ...input, @@ -435,6 +438,7 @@ export default class RecipeWrapper { fetchResponse: Response; } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } | GeneralErrorResponse > { return Recipe.getInstanceOrThrow().recipeImplementation.authenticateCredentialWithSignIn({ @@ -483,6 +487,7 @@ export default class RecipeWrapper { | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } > { return Recipe.getInstanceOrThrow().recipeImplementation.registerCredentialWithRecoverAccount({ ...input, diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index d6fa7cb2..dfebf320 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -363,6 +363,13 @@ export default function getRecipeImplementation( return { status: "AUTHENTICATOR_ALREADY_REGISTERED" }; } + if ( + error.name === "NotSupportedError" || + error.message === "WebAuthn is not supported in this browser" + ) { + return { status: "WEBAUTHN_NOT_SUPPORTED", error: error }; + } + return { status: "FAILED_TO_REGISTER_USER", error: error, @@ -410,6 +417,13 @@ export default function getRecipeImplementation( try { authenticationResponse = await startAuthentication({ optionsJSON: authenticationOptions }); } catch (error: any) { + if ( + error.name === "NotSupportedError" || + error.message === "WebAuthn is not supported in this browser" + ) { + return { status: "WEBAUTHN_NOT_SUPPORTED", error: error }; + } + return { status: "FAILED_TO_AUTHENTICATE_USER", error: error, diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index a2d4c5ae..ae05812c 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -238,6 +238,7 @@ export type RecipeInterface = { } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } >; authenticateCredential: (input: { authenticationOptions: AuthenticationOptions }) => Promise< | { @@ -245,6 +246,7 @@ export type RecipeInterface = { authenticationResponse: AuthenticationResponseJSON; } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } >; registerCredentialWithSignUp: (input: { email: string; @@ -274,6 +276,7 @@ export type RecipeInterface = { | { status: "EMAIL_ALREADY_EXISTS_ERROR"; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } >; authenticateCredentialWithSignIn: (input: { options?: RecipeFunctionOptions; userContext: any }) => Promise< | { @@ -285,6 +288,7 @@ export type RecipeInterface = { | { status: "INVALID_CREDENTIALS_ERROR"; fetchResponse: Response } | { status: "SIGN_IN_NOT_ALLOWED"; reason: string; fetchResponse: Response } | { status: "FAILED_TO_AUTHENTICATE_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } | GeneralErrorResponse >; registerCredentialWithRecoverAccount: (input: { @@ -313,5 +317,6 @@ export type RecipeInterface = { | { status: "INVALID_AUTHENTICATOR_ERROR"; reason: string; fetchResponse: Response } | { status: "AUTHENTICATOR_ALREADY_REGISTERED" } | { status: "FAILED_TO_REGISTER_USER"; error: any } + | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } >; }; From 597189688796e7b6de46505d1fa9269799dc2004 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 21 Feb 2025 11:15:46 +0530 Subject: [PATCH 46/46] Add function for checking if browser supports webauthn --- lib/build/recipe/webauthn/index.d.ts | 13 +++++++ lib/build/recipe/webauthn/index.js | 8 ++++- .../recipe/webauthn/recipeImplementation.js | 34 +++++++++++++++++++ lib/build/recipe/webauthn/types.d.ts | 11 ++++++ lib/ts/recipe/webauthn/index.ts | 16 +++++++++ .../recipe/webauthn/recipeImplementation.ts | 17 ++++++++++ lib/ts/recipe/webauthn/types.ts | 11 ++++++ 7 files changed, 109 insertions(+), 1 deletion(-) diff --git a/lib/build/recipe/webauthn/index.d.ts b/lib/build/recipe/webauthn/index.d.ts index 2a3a89c3..ff4ee1e8 100644 --- a/lib/build/recipe/webauthn/index.d.ts +++ b/lib/build/recipe/webauthn/index.d.ts @@ -527,6 +527,17 @@ export default class RecipeWrapper { error: any; } >; + static doesBrowserSupportWebAuthn(): Promise< + | { + status: "OK"; + browserSupportsWebauthn: boolean; + platformAuthenticatorIsAvailable: boolean; + } + | { + status: "ERROR"; + error: any; + } + >; } declare const init: typeof RecipeWrapper.init; declare const getRegisterOptions: typeof RecipeWrapper.getRegisterOptions; @@ -541,6 +552,7 @@ declare const authenticateCredentialWithSignIn: typeof RecipeWrapper.authenticat declare const registerCredentialWithRecoverAccount: typeof RecipeWrapper.registerCredentialWithRecoverAccount; declare const registerCredential: typeof RecipeWrapper.registerCredential; declare const authenticateCredential: typeof RecipeWrapper.authenticateCredential; +declare const doesBrowserSupportWebAuthn: typeof RecipeWrapper.doesBrowserSupportWebAuthn; export { init, getRegisterOptions, @@ -555,5 +567,6 @@ export { registerCredentialWithRecoverAccount, registerCredential, authenticateCredential, + doesBrowserSupportWebAuthn, RecipeInterface, }; diff --git a/lib/build/recipe/webauthn/index.js b/lib/build/recipe/webauthn/index.js index 1fd2eb42..6b389601 100644 --- a/lib/build/recipe/webauthn/index.js +++ b/lib/build/recipe/webauthn/index.js @@ -28,7 +28,8 @@ var __assign = return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.authenticateCredential = +exports.doesBrowserSupportWebAuthn = + exports.authenticateCredential = exports.registerCredential = exports.registerCredentialWithRecoverAccount = exports.authenticateCredentialWithSignIn = @@ -276,6 +277,9 @@ var RecipeWrapper = /** @class */ (function () { }) ); }; + RecipeWrapper.doesBrowserSupportWebAuthn = function () { + return recipe_1.default.getInstanceOrThrow().recipeImplementation.doesBrowserSupportWebAuthn(); + }; return RecipeWrapper; })(); exports.default = RecipeWrapper; @@ -305,3 +309,5 @@ var registerCredential = RecipeWrapper.registerCredential; exports.registerCredential = registerCredential; var authenticateCredential = RecipeWrapper.authenticateCredential; exports.authenticateCredential = authenticateCredential; +var doesBrowserSupportWebAuthn = RecipeWrapper.doesBrowserSupportWebAuthn; +exports.doesBrowserSupportWebAuthn = doesBrowserSupportWebAuthn; diff --git a/lib/build/recipe/webauthn/recipeImplementation.js b/lib/build/recipe/webauthn/recipeImplementation.js index f4625f05..5cbacc36 100644 --- a/lib/build/recipe/webauthn/recipeImplementation.js +++ b/lib/build/recipe/webauthn/recipeImplementation.js @@ -164,6 +164,7 @@ var querier_1 = require("../../querier"); var recipe_1 = require("../multitenancy/recipe"); var browser_1 = require("@simplewebauthn/browser"); function getRecipeImplementation(recipeImplInput) { + var _this = this; var querier = new querier_1.default(recipeImplInput.recipeId, recipeImplInput.appInfo); return { getRegisterOptions: function (_a) { @@ -749,6 +750,39 @@ function getRecipeImplementation(recipeImplInput) { }); }); }, + doesBrowserSupportWebAuthn: function () { + return __awaiter(_this, void 0, void 0, function () { + var isPlatformAuthenticatorAvailable, error_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, (0, browser_1.platformAuthenticatorIsAvailable)()]; + case 1: + isPlatformAuthenticatorAvailable = _a.sent(); + return [ + 2 /*return*/, + { + status: "OK", + browserSupportsWebauthn: (0, browser_1.browserSupportsWebAuthn)(), + platformAuthenticatorIsAvailable: isPlatformAuthenticatorAvailable, + }, + ]; + case 2: + error_3 = _a.sent(); + return [ + 2 /*return*/, + { + status: "ERROR", + error: error_3, + }, + ]; + case 3: + return [2 /*return*/]; + } + }); + }); + }, }; } exports.default = getRecipeImplementation; diff --git a/lib/build/recipe/webauthn/types.d.ts b/lib/build/recipe/webauthn/types.d.ts index a6e8d74e..d9e778e6 100644 --- a/lib/build/recipe/webauthn/types.d.ts +++ b/lib/build/recipe/webauthn/types.d.ts @@ -415,4 +415,15 @@ export declare type RecipeInterface = { error: any; } >; + doesBrowserSupportWebAuthn: () => Promise< + | { + status: "OK"; + browserSupportsWebauthn: boolean; + platformAuthenticatorIsAvailable: boolean; + } + | { + status: "ERROR"; + error: any; + } + >; }; diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index 3705b7d3..967928f8 100644 --- a/lib/ts/recipe/webauthn/index.ts +++ b/lib/ts/recipe/webauthn/index.ts @@ -494,6 +494,20 @@ export default class RecipeWrapper { userContext: input?.userContext, }); } + + static doesBrowserSupportWebAuthn(): Promise< + | { + status: "OK"; + browserSupportsWebauthn: boolean; + platformAuthenticatorIsAvailable: boolean; + } + | { + status: "ERROR"; + error: any; + } + > { + return Recipe.getInstanceOrThrow().recipeImplementation.doesBrowserSupportWebAuthn(); + } } const init = RecipeWrapper.init; @@ -509,6 +523,7 @@ const authenticateCredentialWithSignIn = RecipeWrapper.authenticateCredentialWit const registerCredentialWithRecoverAccount = RecipeWrapper.registerCredentialWithRecoverAccount; const registerCredential = RecipeWrapper.registerCredential; const authenticateCredential = RecipeWrapper.authenticateCredential; +const doesBrowserSupportWebAuthn = RecipeWrapper.doesBrowserSupportWebAuthn; export { init, @@ -524,5 +539,6 @@ export { registerCredentialWithRecoverAccount, registerCredential, authenticateCredential, + doesBrowserSupportWebAuthn, RecipeInterface, }; diff --git a/lib/ts/recipe/webauthn/recipeImplementation.ts b/lib/ts/recipe/webauthn/recipeImplementation.ts index dfebf320..6d1d7e53 100644 --- a/lib/ts/recipe/webauthn/recipeImplementation.ts +++ b/lib/ts/recipe/webauthn/recipeImplementation.ts @@ -21,6 +21,8 @@ import { GeneralErrorResponse, User } from "../../types"; import Multitenancy from "../multitenancy/recipe"; import { AuthenticationResponseJSON, + browserSupportsWebAuthn, + platformAuthenticatorIsAvailable, RegistrationResponseJSON, startAuthentication, startRegistration, @@ -491,6 +493,21 @@ export default function getRecipeImplementation( userContext, }); }, + doesBrowserSupportWebAuthn: async () => { + try { + const isPlatformAuthenticatorAvailable = await platformAuthenticatorIsAvailable(); + return { + status: "OK", + browserSupportsWebauthn: browserSupportsWebAuthn(), + platformAuthenticatorIsAvailable: isPlatformAuthenticatorAvailable, + }; + } catch (error: any) { + return { + status: "ERROR", + error: error, + }; + } + }, }; } diff --git a/lib/ts/recipe/webauthn/types.ts b/lib/ts/recipe/webauthn/types.ts index ae05812c..f9dac691 100644 --- a/lib/ts/recipe/webauthn/types.ts +++ b/lib/ts/recipe/webauthn/types.ts @@ -319,4 +319,15 @@ export type RecipeInterface = { | { status: "FAILED_TO_REGISTER_USER"; error: any } | { status: "WEBAUTHN_NOT_SUPPORTED"; error: any } >; + doesBrowserSupportWebAuthn: () => Promise< + | { + status: "OK"; + browserSupportsWebauthn: boolean; + platformAuthenticatorIsAvailable: boolean; + } + | { + status: "ERROR"; + error: any; + } + >; };