Skip to content

Commit

Permalink
Expose function for authentication and sign in through recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Dec 11, 2024
1 parent 04f3f57 commit 6054dcb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/ts/recipe/webauthn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -367,4 +405,5 @@ export {
generateRecoverAccountToken,
recoverAccount,
registerAndSignup,
authenticateAndSignIn,
};

0 comments on commit 6054dcb

Please sign in to comment.