Skip to main content

Installation

Find the anon key with npx @insforge/cli secrets get ANON_KEY, or in the dashboard: click Install and open API Keys.

signUp()

Create a new user account with email and password.

Parameters

  • email (string, required) - User’s email address
  • password (string, required) - User’s password
  • name (string, optional) - User’s display name
  • redirectTo (string, optional) - Used for link-based email verification. The email link always opens an InsForge backend endpoint first; after the token is verified, InsForge redirects the browser to this URL with the verification result. Required when verifyEmailMethod is set to link. This URL must be included in allowedRedirectUrls. Recommended: use your app’s sign-in page.

Returns

When requireEmailVerification is true, accessToken will be null until the user verifies their email. InsForge sends a verification email with either a link or a 6-digit code, based on your dashboard configuration (verifyEmailMethod). For code verification, implement a page that prompts the user to enter the code (see verifyEmail()). For link verification, provide a redirectTo URL that should receive the browser after InsForge verifies the token. Recommended: use your sign-in page as redirectTo, then show a success message and ask the user to sign in with their email and password.

Example

Output


signInWithPassword()

Sign in an existing user with email and password.

Parameters

  • email (string, required) - User’s email address
  • password (string, required) - User’s password

Returns

Example

Output


signInWithOAuth()

Start OAuth authentication flow with configured providers (built-in providers like Google/GitHub, plus any custom provider key configured from the dashboard).

Parameters

  • provider (string, required) - OAuth provider key (e.g., google, github, or custom provider key like okta-company)
  • redirectTo (string, required) - URL to redirect after authentication
  • additionalParams (Record<string, string>, optional) - Provider-specific OAuth hints such as Google’s prompt=select_account
  • skipBrowserRedirect (boolean, optional) - If true, returns OAuth URL without auto-redirecting (for server-rendered or mobile flows)

Returns

After OAuth redirect, SDK automatically detects the callback insforge_code, exchanges it for a session, and saves the session automatically.

Example

additionalParams is for provider-specific optional hints only. Do not pass server-owned OAuth fields such as client_id, redirect_uri, code_challenge, state, response_type, or scope; InsForge sets those values on the server and ignores colliding client-provided keys.
Custom providers must be configured first in the InsForge dashboard under Auth Methods with client credentials and an OIDC discovery URL.

Output


signOut()

Sign out the current user and clear session.

Parameters

None

Returns

Example

Output


getCurrentUser()

Get the currently signed-in user. For browser apps, call auth.getCurrentUser() during startup. If a valid httpOnly refresh cookie is present, the SDK will refresh the session automatically before returning the user. For server mode, call refreshSession({ refreshToken }) explicitly when you need to refresh an expired access token.

Parameters

None

Returns

Example

Output


getProfile()

Get any user’s public profile by ID. Returns a flat profile object with all fields at the top level.

Parameters

  • userId (string, required) - User ID to fetch profile for

Returns

Example

Output


setProfile()

Update current user’s profile in users table. Supports any dynamic fields and returns the updated profile as a flat object.

Parameters

  • profile (object) - A key-value map of profile fields to update. Any fields are accepted.
Common fields:
  • name (predefined, string) - User’s display name
  • avatar_url (predefined, string) - Profile picture URL

Returns

Example

Output


resendVerificationEmail()

Resend email verification when the previous OTP has expired or was not received. Uses the method configured in auth settings (verifyEmailMethod). When method is code, sends a 6-digit numeric code. When method is link, sends a browser verification link that goes through an InsForge backend endpoint first.
This endpoint prevents user enumeration by returning success even if the email doesn’t exist.

Parameters

  • email (string, required) - User’s email address
  • redirectTo (string, optional) - Used for link-based email verification. The email link always opens an InsForge backend endpoint first; after the token is verified, InsForge redirects the browser to this URL with the verification result. Required when verifyEmailMethod is set to link. This URL must be included in allowedRedirectUrls. Recommended: use your app’s sign-in page.

Returns

Example

Output


verifyEmail()

Verify an email address with a 6-digit code. For link-based verification, users should click the email link, which opens GET /api/auth/email/verify-link in the browser. Successfully verified users who use this code endpoint will receive a session token. For link-based verification, your frontend should handle the browser redirect like this:
  • Success: ?insforge_status=success&insforge_type=verify_email
  • Error: ?insforge_status=error&insforge_type=verify_email&insforge_error=...
  • insforge_status: Result of the browser link flow. For verification, values are success or error.
  • insforge_type: Flow identifier. For verification links this is always verify_email.
  • insforge_error: Present only when insforge_status=error. Human-readable error message for display or logging.
Recommended handling: use your sign-in page as redirectTo. When insforge_status=success, show a confirmation message and ask the user to sign in with their email and password.

Parameters

  • email (string, required) - User’s email address
  • otp (string, required) - 6-digit verification code

Returns

Example

Output


sendResetPasswordEmail()

Send password reset email using the method configured in auth settings (resetPasswordMethod). When method is code, sends a 6-digit numeric code for two-step flow. When method is link, sends a browser reset link that goes through an InsForge backend endpoint first.
This endpoint prevents user enumeration by returning success even if the email doesn’t exist.

Parameters

  • email (string, required) - User’s email address
  • redirectTo (string, optional) - Used for link-based password reset. The email link always opens an InsForge backend endpoint first; InsForge then redirects the browser to this URL with the reset token in the query string so your app can render its own reset-password page. Required when resetPasswordMethod is set to link. This URL must be included in allowedRedirectUrls. Recommended: use your app’s dedicated reset-password page.

Returns

Example

Output


exchangeResetPasswordToken()

Exchange a 6-digit reset password code for a reset token. This is step 1 of the two-step password reset flow (only used when resetPasswordMethod is code).
This endpoint is not used when resetPasswordMethod is link, because the browser reset-link flow uses the emailed link token directly.

Parameters

  • email (string, required) - User’s email address
  • code (string, required) - 6-digit code from the email

Returns

Example

Output


resetPassword()

Reset user password with a token. The token can be:
  • Magic link token: Provided in the reset page URL from sendResetPasswordEmail when method is link
  • Reset token: From exchangeResetPasswordToken after code verification when method is code

Parameters

  • newPassword (string, required) - New password for the user
  • otp (string, required) - Reset token or magic link token
For link-based password reset, your frontend should handle the browser redirect like this:
  • Ready to reset: ?token=...&insforge_status=ready&insforge_type=reset_password
  • Error: ?insforge_status=error&insforge_type=reset_password&insforge_error=...
  • token: Present only when insforge_status=ready. Pass this value to resetPassword({ otp }).
  • insforge_status: Result of the browser link flow. For reset links, values are ready or error.
  • insforge_type: Flow identifier. For reset links this is always reset_password.
  • insforge_error: Present only when insforge_status=error. Human-readable error message for display or logging.
Only render the reset-password form when insforge_status=ready and token is present.

Returns

Example

Output


Error Handling

All auth methods return structured errors: