Skip to content

Commit

Permalink
Add wrapper definitions for sign in with options and signup
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Dec 9, 2024
1 parent 7fd7d1c commit f78b025
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions lib/ts/recipe/webauthn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 } & (
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f78b025

Please sign in to comment.