diff --git a/lib/ts/recipe/webauthn/index.ts b/lib/ts/recipe/webauthn/index.ts index caa6c92..1805103 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, };