Skip to content

Commit

Permalink
Add recover account method from webauthn recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Dec 9, 2024
1 parent 25cf6dc commit 24aa206
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion lib/ts/recipe/webauthn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
};

0 comments on commit 24aa206

Please sign in to comment.