From 24aa20613dd8ff475bbf58b6f1ea7349bccfdf14 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 9 Dec 2024 18:28:50 +0530 Subject: [PATCH] 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 cf9338b..9643144 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, +};