### Install Project Dependencies with npm Source: https://github.com/supertokens/supertokens-web-js/blob/master/examples/react/with-thirdpartyemailpassword/README.md Installs all necessary packages for the demo application using npm. This is a prerequisite for running the project. ```bash npm install ``` -------------------------------- ### Run Demo App with npm Source: https://github.com/supertokens/supertokens-web-js/blob/master/examples/react/with-thirdpartyemailpassword/README.md Starts the development server for the SuperTokens React demo application. The app will be accessible at http://localhost:3000. ```bash npm run dev ``` -------------------------------- ### Initialize Multi-Factor Authentication Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_multifactorauth.html Initializes the Multi-Factor Authentication recipe with optional configuration. This function should be called once when your application starts. ```APIDOC ## init() ### Description Initializes the Multi-Factor Authentication recipe. ### Method Function call ### Endpoint N/A (Client-side initialization) ### Parameters #### Optional config: UserInput - **options** (RecipeFunctionOptions) - Optional configuration for recipe functions. - **userContext** (any) - Optional user context object. ### Request Example ```javascript import { SuperTokens } from 'supertokens-web-js'; import MultiFactorAuth from 'supertokens-web-js/recipe/multifactorauth'; SuperTokens.init({ recipes: [ MultiFactorAuth.init({ // Optional configuration here }) ] }); ``` ### Response Returns a `CreateRecipeFunction` object for the MFA recipe. ``` -------------------------------- ### Multitenancy - Get Login Methods Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_multitenancy.default.html Retrieves the enabled login methods and their configurations from the backend for a given tenant. ```APIDOC ## GET /recipe/multitenancy/loginmethods ### Description Gets enabled login methods and their configuration from the backend. ### Method GET ### Endpoint /recipe/multitenancy/loginmethods ### Parameters #### Query Parameters - **tenantId** (string) - Optional - The ID of the tenant to retrieve login methods for. - **options** (object) - Optional - Additional options for the request. - **sessionRecipe** (object) - Optional - The session recipe instance to use. - **userContext** (any) - Optional - User context for the request. ### Request Example ```json { "tenantId": "your_tenant_id", "options": {}, "userContext": {} } ``` ### Response #### Success Response (200) - **status** (string) - OK - **firstFactors** (string[]) - An array of strings representing the first factors of login methods. - **thirdParty** (object) - Information about third-party login providers. - **providers** (object[]) - An array of third-party provider objects. - **id** (string) - The ID of the provider. - **name** (string) - The name of the provider. #### Response Example ```json { "status": "OK", "firstFactors": ["emailpassword", "passwordless"], "thirdParty": { "providers": [ {"id": "google", "name": "Google"}, {"id": "facebook", "name": "Facebook"} ] } } ``` #### Error Response - **status** (string) - GENERAL_ERROR - **message** (string) - A message describing the error. ``` -------------------------------- ### resyncSessionAndFetchMFAInfo Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_multifactorauth.default.html Loads information about available MFA factors and updates session requirements. It fetches the current MFA setup status for the user. ```APIDOC ## POST /recipe/multifactorauth/session/resync ### Description Loads information about what factors the current session can set up/complete and updates the requirements in the session payload. This is typically used to refresh the MFA status after certain user actions or session events. ### Method POST ### Endpoint /recipe/multifactorauth/session/resync ### Parameters #### Request Body - **input** (object) - Optional - Contains options and user context. - **options** (object) - Optional - Recipe function options, potentially including configuration for the request. - **userContext** (any) - Optional - Contextual information for the user. ### Request Example ```json { "input": { "options": {}, "userContext": {} } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates "OK" on successful completion. - **emails** (object) - A record of user emails and associated MFA factors. - **phoneNumbers** (object) - A record of user phone numbers and associated MFA factors. - **factors** (object) - Information about available MFA factors. - **fetchResponse** (object) - The raw Response object from the fetch API. #### Response Example ```json { "status": "OK", "emails": { "user@example.com": ["totp", "webauthn"] }, "phoneNumbers": { "+1234567890": ["sms"] }, "factors": { "totp": {"setupStatus": "SETUP_COMPLETED"}, "webauthn": {"setupStatus": "SETUP_NOT_NEEDED"} }, "fetchResponse": {} } ``` ``` -------------------------------- ### Get Sign-In Options (WebAuthn) Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Fetches sign-in options for WebAuthn, enabling users to initiate the sign-in flow. This function requires RecipeFunctionOptions and userContext. It can return authentication options or specific error responses. ```typescript getSignInOptions(input: { options?: RecipeFunctionOptions; userContext: any; }): Promise ``` -------------------------------- ### Create a New TOTP Device Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_totp.html Creates a new TOTP device for the current user. Returns the device name, secret, and QR code string required for setup. ```typescript import Totp from "supertokens-web-js/recipe/totp"; const response = await Totp.createDevice({ deviceName: "my-phone" }); if (response.status === "OK") { console.log(response.qrCodeString); } ``` -------------------------------- ### GET getLoginMethods Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_multitenancy.html Retrieves the enabled login methods and their configuration for a specific tenant. ```APIDOC ## GET getLoginMethods ### Description Fetches the enabled login methods (e.g., emailpassword, thirdparty) and their configuration for a given tenant. This is useful for dynamically rendering login UI components. ### Method GET ### Parameters #### Input Object - **tenantId** (string) - Optional - The ID of the tenant to fetch login methods for. - **options** (RecipeFunctionOptions) - Optional - Additional configuration options for the request. - **userContext** (any) - Required - Context object for the request. ### Response #### Success Response (200) - **status** (string) - Always "OK" on success. - **firstFactors** (string[]) - List of enabled first-factor authentication methods. - **thirdParty** (object) - Configuration for third-party providers. - **providers** (array) - List of enabled third-party providers with their IDs and names. - **fetchResponse** (Response) - The raw fetch response object. ### Error Handling - Throws `STGeneralError` if the backend returns `status: "GENERAL_ERROR"`. ``` -------------------------------- ### Create TOTP Device Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Initializes a new TOTP device for the user, returning the secret and QR code string required for authenticator app setup. ```javascript import { createDevice } from "supertokens-web-js/recipe/totp"; async function setupTOTP() { const response = await createDevice({ deviceName: "My Authenticator App" }); if (response.status === "OK") { console.log("Device name:", response.deviceName); console.log("Secret:", response.secret); console.log("QR Code URL:", response.qrCodeString); return response; } else if (response.status === "DEVICE_ALREADY_EXISTS_ERROR") { console.error("A device with this name already exists"); } } ``` -------------------------------- ### Get Sign-In Options for WebAuthn Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_webauthn.default.html Retrieves options necessary for authenticating a user via WebAuthn. It takes user context and optional configuration as input, returning a challenge for verification or an error response. ```typescript getSignInOptions(input: { options?: RecipeFunctionOptions; userContext: any; }): Promise ``` -------------------------------- ### Initialize OAuth2 Provider Recipe Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_oauth2provider.default.html Initializes the OAuth2 provider recipe within the SuperTokens SDK. This setup is required before using other OAuth2-related functions. ```typescript import OAuth2Provider from "supertokens-web-js/recipe/oauth2provider"; OAuth2Provider.init({ /* configuration options */ }); ``` -------------------------------- ### Get Registration Options (WebAuthn) Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Retrieves registration options for WebAuthn, used to initiate the user registration process. It handles different scenarios including recovering an account or dealing with invalid email formats. Dependencies include RecipeFunctionOptions and userContext. ```typescript getRegisterOptions(input: { options?: RecipeFunctionOptions; userContext: any; } & { email: string; } & { options?: RecipeFunctionOptions; userContext: any; } & { recoverAccountToken: string; }): Promise ``` -------------------------------- ### Get Registration Options for WebAuthn Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_webauthn.default.html Retrieves options required to register a new WebAuthn device. It takes user context and email as input and returns a challenge to be fulfilled for successful device addition. Handles errors like invalid email or recovery token. ```typescript getRegisterOptions(input: { options?: RecipeFunctionOptions; userContext: any; } & { email: string; } & { options?: RecipeFunctionOptions; userContext: any; } & { recoverAccountToken: string; }): Promise<{ attestation: "none" | "indirect" | "direct" | "enterprise"; authenticatorSelection: { requireResidentKey: boolean; residentKey: ResidentKey; userVerification: UserVerification; }; challenge: string; createdAt: string; excludeCredentials: { id: string; transports: ("ble" | "hybrid" | "internal" | "nfc" | "usb") []; type: "public-key"; }[]; expiresAt: string; fetchResponse: Response; pubKeyCredParams: { alg: number; type: "public-key"; }[]; rp: { id: string; name: string; }; status: "OK"; timeout: number; user: { displayName: string; id: string; name: string; }; webauthnGeneratedOptionsId: string; } | { fetchResponse: Response; status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"; } | { err: string; fetchResponse: Response; status: "INVALID_EMAIL_ERROR"; } | { fetchResponse: Response; status: "INVALID_OPTIONS_ERROR"; }> ``` -------------------------------- ### Initiate Passwordless Authentication with createCode Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Starts the passwordless authentication flow by sending an OTP or magic link to the user's email or phone number. It requires the 'supertokens-web-js' library and returns a device ID and flow type upon success. ```javascript import { createCode } from "supertokens-web-js/recipe/passwordless"; // Send OTP/magic link to email async function startEmailPasswordless(email) { const response = await createCode({ email }); if (response.status === "OK") { console.log("Device ID:", response.deviceId); console.log("Flow type:", response.flowType); // "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK" // Store these for consuming the code later return response; } else if (response.status === "SIGN_IN_UP_NOT_ALLOWED") { console.error("Sign in/up not allowed:", response.reason); } } // Send OTP/magic link to phone async function startPhonePasswordless(phoneNumber) { const response = await createCode({ phoneNumber }); if (response.status === "OK") { console.log("Code sent to:", phoneNumber); return response; } } ``` -------------------------------- ### GET /webauthn/authenticateCredential Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Triggers the browser's WebAuthn authentication flow to get credentials. ```APIDOC ## GET /webauthn/authenticateCredential ### Description Initiates the browser-based WebAuthn authentication process to retrieve a credential for signing in. ### Method GET ### Parameters #### Query Parameters - **authenticationOptions** (Object) - Required - Options for the WebAuthn authentication flow. - **userContext** (any) - Required - Contextual data. ### Response #### Success Response (200) - **status** (string) - "OK" - **authenticationResponse** (AuthenticationResponseJSON) - The resulting credential data. #### Error Responses - **status** ("FAILED_TO_AUTHENTICATE_USER" | "WEBAUTHN_NOT_SUPPORTED") - Indicates failure to authenticate or lack of browser support. ``` -------------------------------- ### GET /session/doesSessionExist Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Checks if a valid session exists for the current user. ```APIDOC ## GET /session/doesSessionExist ### Description Checks if a valid session exists for the current user. ### Method GET ### Response #### Success Response (200) - **boolean** - Returns true if a session exists, false otherwise. ``` -------------------------------- ### init() Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_oauth2provider.html Initializes the OAuth2 Provider recipe with the provided configuration. ```APIDOC ## init() ### Description Initializes the OAuth2 Provider recipe. This must be called before using other recipe functions. ### Parameters #### Request Body - **config** (UserInput) - Optional - Configuration object for the recipe. ### Response #### Success Response (200) - **returns** (CreateRecipeFunction) - Returns the recipe function instance. ``` -------------------------------- ### Initialize WebAuthn Recipe Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Initializes the WebAuthn recipe with configuration options. ```APIDOC ## init ### Description Initializes the WebAuthn recipe with the provided configuration. This function must be called once before using any other WebAuthn recipe functions. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Input - **config** (object) - Optional - Configuration options for the WebAuthn recipe. - (Refer to `UserInput` type for detailed configuration options) ### Request Example ```javascript import { WebAuthn } from "supertokens-web-js/recipe/webauthn"; WebAuthn.init({ // configuration options }); ``` ### Response Returns a function that can be used to interact with the WebAuthn recipe. The exact return type is `CreateRecipeFunction`. ``` -------------------------------- ### getRedirectURLToContinueOAuthFlow Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_oauth2provider.html Gets the redirect URL required to continue the OAuth flow. ```APIDOC ## getRedirectURLToContinueOAuthFlow ### Description Returns the URL to which the frontend should redirect the user to continue the OAuth authentication process. ### Parameters #### Request Body - **loginChallenge** (string) - Required - The unique identifier for the login challenge. - **options** (RecipeFunctionOptions) - Optional - Configuration options. - **userContext** (any) - Optional - Custom context data. ### Response #### Success Response (200) - **fetchResponse** (Response) - The raw fetch response object. - **frontendRedirectTo** (string) - The URL to redirect the user to. - **status** (string) - Status string, expected to be "OK". ``` -------------------------------- ### Multitenancy - Get Tenant ID Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_multitenancy.default.html Retrieves the current tenant ID. ```APIDOC ## GET /recipe/multitenancy/tenantid ### Description Gets the current tenant ID. ### Method GET ### Endpoint /recipe/multitenancy/tenantid ### Parameters #### Query Parameters - **userContext** (any) - Optional - User context for the request. ### Request Example ```json { "userContext": {} } ``` ### Response #### Success Response (200) - **tenantId** (string | undefined) - The ID of the current tenant, or undefined if not set. #### Response Example ```json "your_tenant_id" ``` ``` -------------------------------- ### Static init() Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/index.default.html Initializes the SuperTokens Web JS SDK with the provided configuration object. ```APIDOC ## Static init ### Description Initializes the SuperTokens SDK. This must be called before any other SuperTokens functions are used in your application. ### Method Static Method ### Parameters #### Request Body - **config** (SuperTokensConfig) - Required - The configuration object containing API domain, app info, and enabled recipes. ### Request Example ```javascript SuperTokens.init({ appInfo: { apiDomain: "https://api.example.com", appName: "MyApp" }, recipeList: [ // Add recipes here ] }); ``` ### Response #### Success Response (void) - **Returns** (void) - The function does not return a value. ``` -------------------------------- ### init (Multitenancy) Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_multitenancy.default.html Initializes the Multitenancy recipe for the SuperTokens web-js SDK. ```APIDOC ## init ### Description Initializes the Multitenancy recipe. This function must be called to configure the multi-tenant capabilities within the SuperTokens SDK. ### Method N/A (SDK Method) ### Parameters #### Optional Parameters - **config** (UserInput) - Optional - Configuration object for the multitenancy recipe. ### Returns - **CreateRecipeFunction<"GET_LOGIN_METHODS">** - Returns a function to create the recipe instance. ### Usage Example ```javascript import Multitenancy from "supertokens-web-js/recipe/multitenancy"; Multitenancy.init({ // configuration options }); ``` ``` -------------------------------- ### GET /doesEmailExist Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_passwordless.html Checks if a user with the given email already exists in the system. ```APIDOC ## GET /doesEmailExist ### Description Checks if an email is already registered. ### Method GET ### Endpoint /doesEmailExist ### Parameters #### Query Parameters - **email** (string) - Required - The email to check. ### Response #### Success Response (200) - **doesExist** (boolean) - Whether the email exists. #### Response Example { "status": "OK", "doesExist": true } ``` -------------------------------- ### GET /listDevices Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_totp.html Retrieves a list of all TOTP devices associated with the current user. ```APIDOC ## GET /listDevices ### Description Lists all TOTP devices registered to the current user, including their verification status. ### Method GET ### Parameters #### Query Parameters - **options** (RecipeFunctionOptions) - Optional - Configuration options. - **userContext** (any) - Optional - Custom context data. ### Response #### Success Response (200) - **status** (string) - "OK" - **devices** (array) - List of device objects containing name, period, skew, and verified status. #### Response Example { "status": "OK", "devices": [ { "name": "my-phone", "period": 30, "skew": 0, "verified": true } ] } ``` -------------------------------- ### Sign Up User with Email and Password (JavaScript) Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_emailpassword.default.html This function allows users to sign up with their email and password. It takes an array of form fields, including email and password, and returns a promise that resolves with user information on success or an error object on failure. Ensure the backend SDKs are configured to handle email and password sign-ups. ```javascript signUp({ formFields: [ { id: 'email', value: 'test@example.com' }, { id: 'password', value: 'password123' } ] }); ``` -------------------------------- ### POST /auth/signup Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Registers a new user with email and password credentials. Upon success, a session is automatically established. ```APIDOC ## POST /auth/signup ### Description Registers a new user with email and password credentials. Returns user information on success or validation errors for invalid form fields. ### Method POST ### Endpoint /auth/signup ### Parameters #### Request Body - **formFields** (array) - Required - An array of objects containing 'id' and 'value' for email and password fields. ### Request Example { "formFields": [ { "id": "email", "value": "user@example.com" }, { "id": "password", "value": "securePassword123" } ] } ### Response #### Success Response (200) - **status** (string) - "OK" - **user** (object) - Contains user ID and email information. #### Response Example { "status": "OK", "user": { "id": "uuid-12345", "emails": ["user@example.com"] } } ``` -------------------------------- ### GET getTenantId Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_multitenancy.html Retrieves the current tenant ID associated with the user context. ```APIDOC ## GET getTenantId ### Description Retrieves the tenant ID currently active in the user context. ### Method GET ### Parameters #### Input Object - **userContext** (any) - Required - Context object for the request. ### Response #### Success Response (200) - **Returns** (string | undefined) - The current tenant ID or undefined if not set. ``` -------------------------------- ### POST /signUp Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_emailpassword.html Registers a new user with an email and password. ```APIDOC ## POST /signUp ### Description Registers a new user using the provided email and password credentials. ### Method POST ### Endpoint /signUp ### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. ### Request Example { "email": "user@example.com", "password": "securePassword123" } ### Response #### Success Response (200) - **status** (string) - The status of the registration (e.g., "OK"). #### Response Example { "status": "OK" } ``` -------------------------------- ### GET listDevices Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_totp.default.html Retrieves a list of all TOTP devices associated with the current user. ```APIDOC ## GET listDevices ### Description Lists all TOTP devices of the current user, including their verification status. ### Method GET ### Parameters #### Query Parameters - **options** (RecipeFunctionOptions) - Optional - Custom configuration options. - **userContext** (any) - Optional - Custom user context data. ### Response #### Success Response (200) - **status** (string) - "OK" - **devices** (array) - List of device objects containing name, period, skew, and verified status. ``` -------------------------------- ### init() Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/index.html The init function is used to initialize the SuperTokens SDK with the required configuration object. ```APIDOC ## init(config) ### Description Initializes the SuperTokens SDK. This function must be called before any other SDK methods to ensure proper configuration. ### Method Function Call ### Parameters #### Parameters - **config** (SuperTokensConfig) - Required - The configuration object containing settings for the SDK and its recipes. ### Returns - **void** ### Request Example SuperTokens.init({ appInfo: { appName: "myApp", apiDomain: "https://api.example.com" }, recipeList: [ // List of recipes to use ] }); ``` -------------------------------- ### POST /signUp Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Registers a new user using WebAuthn credentials. ```APIDOC ## POST /signUp ### Description Registers a new user by providing WebAuthn credentials. This method handles the registration process and can optionally link the new user to an existing session. ### Method POST ### Endpoint /signUp ### Parameters #### Request Body - **credential** (RegistrationResponseJSON) - Required - The WebAuthn registration response object. - **options** (RecipeFunctionOptions) - Optional - Configuration options for the recipe function. - **shouldTryLinkingWithSessionUser** (boolean) - Optional - Whether to attempt linking the new user to the current session user. - **userContext** (any) - Required - Contextual information for the user. - **webauthnGeneratedOptionsId** (string) - Required - The ID associated with the generated WebAuthn options. ### Request Example { "credential": { ... }, "webauthnGeneratedOptionsId": "example-id", "userContext": {} } ### Response #### Success Response (200) - **status** (string) - "OK" - **user** (User) - The newly created user object. #### Response Example { "status": "OK", "user": { "id": "user-123", "email": "user@example.com" } } ``` -------------------------------- ### GET /getAuthorisationURLWithQueryParamsAndSetState Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Generates the OAuth authorization URL and stores state for the third-party login flow. ```APIDOC ## GET /getAuthorisationURLWithQueryParamsAndSetState ### Description Generates the OAuth authorization URL and stores state for the third-party login flow. Redirect the user to this URL to initiate social login. ### Method GET ### Parameters #### Query Parameters - **thirdPartyId** (string) - Required - The ID of the provider (e.g., "google", "apple"). - **frontendRedirectURI** (string) - Required - The callback URL on your frontend. ### Response #### Success Response (200) - **authUrl** (string) - The URL to redirect the user to. ``` -------------------------------- ### User Sign Up Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_emailpassword.default.html Registers a new user with the provided email and password. This method is asynchronous and returns user session information upon successful sign-up. ```typescript import EmailPassword from "supertokens-web-js/recipe/emailpassword"; async function userSignUp(email: string, password: string) { const response = await EmailPassword.signUp({ email: email, password: password }); console.log("User signed up:", response); } ``` -------------------------------- ### GET /auth/signup/email/exists Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Checks if an email is already registered in the system, useful for real-time form validation. ```APIDOC ## GET /auth/signup/email/exists ### Description Checks if an email is already registered in the system. Useful for form validation before attempting signup. ### Method GET ### Endpoint /auth/signup/email/exists ### Parameters #### Query Parameters - **email** (string) - Required - The email address to check. ### Request Example /auth/signup/email/exists?email=user@example.com ### Response #### Success Response (200) - **status** (string) - "OK" - **doesExist** (boolean) - True if the email is registered, false otherwise. #### Response Example { "status": "OK", "doesExist": true } ``` -------------------------------- ### Get Login Attempt Info Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_passwordless.html Retrieves information about the current login attempt stored locally. ```APIDOC ## GET /auth/loginAttemptInfo ### Description Get information about the current login attempt from storage. ### Method GET ### Endpoint /auth/loginAttemptInfo ### Parameters #### Query Parameters - **userContext** (any) - Required - User context for the function. ### Response #### Success Response (200) - **deviceId** (string) - The device ID for the login attempt. - **flowType** (PasswordlessFlowType) - The type of passwordless flow. - **preAuthSessionId** (string) - The pre-authentication session ID. - **shouldTryLinkingWithSessionUser** (boolean) - Optional - Whether to try linking with the session user. - **tenantId** (string) - Optional - The tenant ID for the login attempt. - **CustomLoginAttemptInfoProperties** - Optional - Any custom properties associated with the login attempt. #### Response Example ```json { "deviceId": "some_device_id", "flowType": "USER_INPUT_CODE", "preAuthSessionId": "some_session_id" } ``` ``` -------------------------------- ### Initialize Multitenancy Recipe Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_multitenancy.html Initializes the Multitenancy recipe with the provided configuration. This is required to enable multitenancy features in the SuperTokens SDK. ```typescript import Multitenancy from "supertokens-web-js/recipe/multitenancy"; Multitenancy.init({ // UserInput configuration }); ``` -------------------------------- ### Initialize Email Verification Recipe (TypeScript) Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_emailverification.html Initializes the Email Verification recipe with optional configuration. It returns a function to create the recipe instance. Dependencies include the UserInput type for configuration. ```typescript import EmailVerification from "supertokens-web-js/recipe/emailverification"; // Example initialization EmailVerification.init({ // Optional configuration }); ``` -------------------------------- ### Get Login Challenge Info Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_oauth2provider.html Retrieves information related to the login challenge for OAuth2 flows. ```APIDOC ## GET /recipe/oauth2provider/login/challenge ### Description Fetches information required to initiate or continue an OAuth2 login flow, often including a challenge code. ### Method GET ### Endpoint /recipe/oauth2provider/login/challenge ### Parameters #### Query Parameters - **client_id** (string) - Required - The client ID of the OAuth2 provider. - **redirect_uri** (string) - Required - The redirect URI registered with the OAuth2 provider. - **scope** (string) - Optional - The scope of the requested permissions. ### Request Example ``` GET /recipe/oauth2provider/login/challenge?client_id=your_client_id&redirect_uri=http://localhost:3000/callback&scope=profile ``` ### Response #### Success Response (200) - **loginChallengeInfo** (LoginInfo) - An object containing details about the login challenge. #### Response Example ```json { "loginChallengeInfo": { "clientId": "your_client_id", "clientName": "Example Provider", "clientUri": "https://example.com", "logoUri": "https://example.com/logo.png" } } ``` ``` -------------------------------- ### Initialize EmailPassword Recipe Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_emailpassword.html Initializes the EmailPassword recipe with custom configuration. This should be called during the application startup phase. ```typescript import EmailPassword from "supertokens-web-js/recipe/emailpassword"; import SuperTokens from "supertokens-web-js"; SuperTokens.init({ recipeList: [ EmailPassword.init({ override: { functions: (originalImplementation) => ({ ...originalImplementation, // Custom logic here }) } }) ] }); ``` -------------------------------- ### GET doesPhoneNumberExist Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_passwordless.default.html Checks if a user account associated with the provided phone number already exists. ```APIDOC ## GET doesPhoneNumberExist ### Description Checks if a user with the given phone number exists in the system. ### Method GET ### Parameters #### Query Parameters - **phoneNumber** (string) - Required - The phone number to check. ### Response #### Success Response (200) - **doesExist** (boolean) - Whether the user exists. - **status** (string) - "OK" #### Response Example { "status": "OK", "doesExist": false } ``` -------------------------------- ### GET doesEmailExist Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_passwordless.default.html Checks if a user account associated with the provided email address already exists. ```APIDOC ## GET doesEmailExist ### Description Checks if a user with the given email exists in the system. ### Method GET ### Parameters #### Query Parameters - **email** (string) - Required - The email address to check. ### Response #### Success Response (200) - **doesExist** (boolean) - Whether the user exists. - **status** (string) - "OK" #### Response Example { "status": "OK", "doesExist": true } ``` -------------------------------- ### POST /webauthn/signup Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Registers a new user using WebAuthn credentials. ```APIDOC ## POST /webauthn/signup ### Description Registers a new user by verifying the provided WebAuthn registration response. ### Method POST ### Parameters #### Request Body - **credential** (RegistrationResponseJSON) - Required - The WebAuthn registration response. - **webauthnGeneratedOptionsId** (string) - Required - The ID associated with the generated options. - **options** (RecipeFunctionOptions) - Optional - Additional recipe configuration. - **shouldTryLinkingWithSessionUser** (boolean) - Optional - Whether to attempt linking with an existing session user. - **userContext** (any) - Required - Contextual data for the request. ### Response #### Success Response (200) - **status** (string) - "OK" - **user** (User) - The created user object. #### Error Responses - **status** ("EMAIL_ALREADY_EXISTS_ERROR" | "INVALID_CREDENTIALS_ERROR" | "SIGN_UP_NOT_ALLOWED") - Indicates specific failure reasons. ``` -------------------------------- ### GET /session/getAccessTokenPayloadSecurely Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Retrieves the access token payload, which may contain custom claims or user roles. ```APIDOC ## GET /session/getAccessTokenPayloadSecurely ### Description Retrieves the access token payload which can contain custom claims set by the backend. ### Method GET ### Response #### Success Response (200) - **payload** (object) - The decoded access token payload containing user data and custom claims. ``` -------------------------------- ### Get Link Code from URL Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_passwordless.html Retrieves the link code from the current URL's hash fragment. ```APIDOC ## GET /auth/getLinkCode ### Description Reads and returns the link code from the current URL. ### Method GET ### Endpoint /auth/getLinkCode ### Parameters #### Query Parameters - **userContext** (any) - Required - User context for the function. ### Response #### Success Response (200) - **linkCode** (string) - The link code extracted from the URL. #### Response Example ```json { "linkCode": "some_link_code_here" } ``` ``` -------------------------------- ### Sign Up User with WebAuthn Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_webauthn.html Handles the user sign-up process using WebAuthn credentials. It takes registration details and options, returning user information or various error states. Dependencies include Supertokens core and WebAuthn API support. ```typescript signUp({ credential: RegistrationResponseJSON; options?: RecipeFunctionOptions; shouldTryLinkingWithSessionUser?: boolean; userContext: any; webauthnGeneratedOptionsId: string; }): Promise ``` -------------------------------- ### registerCredentialWithSignUp Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_webauthn.default.html Registers a new device and signs up the user with the provided email address using WebAuthn. ```APIDOC ## POST registerCredentialWithSignUp ### Description Registers a new device and signs up the user with the passed email ID. It uses @simplewebauthn/browser to perform the necessary WebAuthn operations. ### Method POST ### Parameters #### Request Body - **email** (string) - Required - The email address of the user. - **options** (RecipeFunctionOptions) - Optional - Configuration options for the recipe. - **shouldTryLinkingWithSessionUser** (boolean) - Optional - Whether to attempt linking with an existing session user. - **userContext** (any) - Required - Context object for the request. ### Response #### Success Response (200) - **status** (string) - Returns "OK" on success. - **user** (User) - The registered user object. #### Response Example { "status": "OK", "user": { "id": "user-id-123", "email": "user@example.com" } } ``` -------------------------------- ### Get Redirect URL to Continue OAuth Flow Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_oauth2provider.html Constructs the redirect URL to continue the OAuth2 authorization code flow. ```APIDOC ## POST /recipe/oauth2provider/redirect/continue ### Description Generates the URL to redirect the user to the OAuth2 provider's authorization endpoint to continue the login flow. ### Method POST ### Endpoint /recipe/oauth2provider/redirect/continue ### Parameters #### Request Body - **loginChallengeInfo** (LoginInfo) - Required - Information about the login challenge. - **authorizationEndpoint** (string) - Required - The authorization endpoint of the OAuth2 provider. - **responseType** (string) - Required - The response type (e.g., 'code'). - **additionalParams** (Record) - Optional - Additional parameters to include in the authorization request. ### Request Example ```json { "loginChallengeInfo": { "clientId": "your_client_id", "clientName": "Example Provider" }, "authorizationEndpoint": "https://example.com/auth", "responseType": "code", "additionalParams": { "prompt": "consent" } } ``` ### Response #### Success Response (200) - **redirectURL** (string) - The full URL to redirect the user to. #### Response Example ```json { "redirectURL": "https://example.com/auth?client_id=your_client_id&redirect_uri=http://localhost:3000/callback&response_type=code&prompt=consent" } ``` ``` -------------------------------- ### POST /createDevice Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_totp.html Creates a new TOTP device for the current user, returning the secret and QR code string. ```APIDOC ## POST /createDevice ### Description Creates a new TOTP device for the authenticated user. Returns a QR code string and secret for setup. ### Method POST ### Parameters #### Request Body - **deviceName** (string) - Optional - The name to assign to the new device. - **options** (RecipeFunctionOptions) - Optional - Configuration options for the request. - **userContext** (any) - Optional - Custom context data. ### Response #### Success Response (200) - **status** (string) - "OK" - **deviceName** (string) - Name of the created device. - **qrCodeString** (string) - String representation of the QR code. - **secret** (string) - The TOTP secret key. #### Response Example { "status": "OK", "deviceName": "my-phone", "qrCodeString": "otpauth://totp/...", "secret": "JBSWY3DPEHPK3PXP" } ``` -------------------------------- ### SuperTokens.init Configuration Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/index.html The init function is used to initialize the SuperTokens SDK with the required configuration object. ```APIDOC ## init(config: SuperTokensConfig) ### Description Initializes the SuperTokens Web JS SDK. This function must be called before any other SuperTokens functions. ### Method Function Call ### Parameters #### Request Body (SuperTokensConfig) - **appInfo** (AppInfoUserInput) - Required - Application specific information for SDK setup. - **recipeList** (CreateRecipeFunction[]) - Required - List of recipes to be used. - **clientType** (string) - Optional - Identifier for the client (e.g., 'web'). - **cookieHandler** (CookieHandlerInput) - Optional - Custom handlers for cookie operations. - **dateProvider** (DateProviderInput) - Optional - Custom provider for SDK timing calculations. - **enableDebugLogs** (boolean) - Optional - Toggle for SDK debug logging. - **experimental** (object) - Optional - Configuration for experimental features and plugins. - **windowHandler** (WindowHandlerInput) - Optional - Custom handlers for Window API access. ### Request Example { "appInfo": { "appName": "myApp", "apiDomain": "https://api.example.com", "websiteDomain": "https://example.com" }, "recipeList": [] } ### Response #### Success Response (void) - **void** - The SDK is initialized successfully. ``` -------------------------------- ### Get Pre Auth Session ID from URL Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_passwordless.html Retrieves the pre-authentication session ID from the current URL's query parameters. ```APIDOC ## GET /auth/getPreAuthSessionId ### Description Reads and returns the pre auth session id from the current URL. ### Method GET ### Endpoint /auth/getPreAuthSessionId ### Parameters #### Query Parameters - **userContext** (any) - Required - User context for the function. ### Response #### Success Response (200) - **preAuthSessionId** (string) - The preAuthSessionId query parameter from the URL. #### Response Example ```json { "preAuthSessionId": "some_pre_auth_session_id" } ``` ``` -------------------------------- ### Register Passkey with Sign Up Source: https://context7.com/supertokens/supertokens-web-js/llms.txt Registers a new WebAuthn credential and performs user sign-up in one flow. Includes a browser support check. ```javascript import { registerCredentialWithSignUp, doesBrowserSupportWebAuthn } from "supertokens-web-js/recipe/webauthn"; async function signUpWithPasskey(email) { const support = await doesBrowserSupportWebAuthn({ userContext: {} }); if (support.status !== "OK" || !support.browserSupportsWebauthn) { console.error("WebAuthn not supported"); return; } const response = await registerCredentialWithSignUp({ email, userContext: {} }); if (response.status === "OK") { console.log("Signed up with passkey:", response.user.id); window.location.href = "/dashboard"; } else if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") { console.error("Email already registered"); } else if (response.status === "WEBAUTHN_NOT_SUPPORTED") { console.error("Browser does not support WebAuthn"); } else if (response.status === "AUTHENTICATOR_ALREADY_REGISTERED") { console.error("This passkey is already registered"); } } ``` -------------------------------- ### Get User ID Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_session.default.html Retrieves the unique identifier for the currently logged-in user. This function is asynchronous and may optionally accept a userContext. ```typescript import Session from "supertokens-web-js/recipe/session"; async function fetchUserId() { const userId = await Session.getUserId(); console.log("User ID:", userId); } ``` -------------------------------- ### OAuth2 Provider Recipe Initialization Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_oauth2provider.html Initializes the OAuth2 Provider recipe with user-defined configurations. ```APIDOC ## POST /recipe/oauth2provider/init ### Description Initializes the OAuth2 Provider recipe. This function should be called once at the start of your application. ### Method POST ### Endpoint /recipe/oauth2provider/init ### Parameters #### Request Body - **options** (UserInput) - Required - User input configuration for the recipe. ### Request Example ```json { "options": { "clients": [ { "clientId": "your_client_id", "clientName": "Example Provider", "clientSecret": "your_client_secret", "authorizationEndpoint": "https://example.com/auth", "tokenEndpoint": "https://example.com/token", "redirectURI": "http://localhost:3000/callback" } ] } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation ('OK'). #### Response Example ```json { "status": "OK" } ``` ``` -------------------------------- ### Get Current Tenant ID Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_multitenancy.html Retrieves the current tenant ID associated with the session or context. Returns a string or undefined if no tenant is set. ```typescript import Multitenancy from "supertokens-web-js/recipe/multitenancy"; const tenantId = await Multitenancy.getTenantId(); ``` -------------------------------- ### Get Redirect URL for OAuth Flow Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/classes/recipe_oauth2provider.default.html Accepts an OAuth2 login request and returns the URL to which the frontend should redirect to continue the OAuth flow. ```typescript const result = await OAuth2Provider.getRedirectURLToContinueOAuthFlow({ loginChallenge: "example-challenge-string" }); window.location.href = result.frontendRedirectTo; ``` -------------------------------- ### POST /signIn Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_emailpassword.html Authenticates an existing user with their email and password. ```APIDOC ## POST /signIn ### Description Authenticates a user and initiates a session. ### Method POST ### Endpoint /signIn ### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. ### Request Example { "email": "user@example.com", "password": "securePassword123" } ### Response #### Success Response (200) - **status** (string) - The status of the authentication (e.g., "OK"). #### Response Example { "status": "OK" } ``` -------------------------------- ### Initialize ThirdParty Recipe Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_thirdparty.html Initializes the ThirdParty recipe with optional user configuration. This function must be called to enable third-party authentication features in the SDK. ```typescript import ThirdParty from "supertokens-web-js/recipe/thirdparty"; ThirdParty.init({ override: { functions: (originalImplementation) => ({ ...originalImplementation, // Custom function overrides }) } }); ``` -------------------------------- ### Get Current User ID Source: https://github.com/supertokens/supertokens-web-js/blob/master/docs/modules/recipe_session.html Retrieves the unique user identifier for the current active session. Returns a promise that resolves to the user ID string. ```typescript const userId = await Session.getUserId(); ```