Skip to main content
This page is part of an AI coding agent skill and is written for agents, not humans. For the human-readable Base44 docs, see the developer documentation.

Auth Module

User authentication, registration, and session management via base44.auth.

Contents


TypeScript Types

User Interface

LoginResponse Interface

Parameter Interfaces

RegisterParams

VerifyOtpParams

ResetPasswordParams

ChangePasswordParams

Provider Type


Methods

Module Interface

Method Reference Table


Examples

Register New User (Complete Flow)

Registration requires email verification before login. Complete flow:
  1. Register - Create the user account
  2. Verification email sent - User receives an OTP code
  3. Verify OTP - User enters code to verify email
  4. Login - User can now log in
Important: Users cannot log in until they complete OTP verification. Attempting to call loginViaEmailPassword before verification will fail.

Login with Email/Password

Login with OAuth Provider

Supported providers: 'google' (enabled by default), 'microsoft', and 'facebook'. Enable Microsoft or Facebook in your app’s authentication settings before using them.

Get Current User

Update User Profile

Check Authentication Status

Logout

Logout redirects the user to the server-side logout endpoint (/api/apps/auth/logout) to clear HTTP-only cookies and the session, then redirects to the given URL (or the current page if omitted). Requires a browser environment.

Protected Route Pattern

Set Authentication Token

Invite User to Application

OTP Verification

Password Reset Flow

Change Password


Error Handling

Common Error Scenarios

The auth module can throw various errors. Here are common scenarios and how to handle them:

Authentication Errors (401/403)

Validation Errors (400/422)

Rate Limiting (429)

Generic Error Handler


Auth Providers

Configure authentication providers in your app dashboard:

Available Providers

Built-in (All Plans):
  • Email/Password - Default, always enabled
  • Google - OAuth authentication
  • Microsoft - OAuth authentication
  • Facebook - OAuth authentication
SSO Providers (Elite Plan):
  • Okta
  • Azure AD
  • GitHub

Using OAuth Providers

  • Google – enabled by default.
  • Microsoft – enable in your app’s authentication settings before use.
  • Facebook – enable in your app’s authentication settings before use.

Environment Availability

Frontend Usage

Backend Functions Usage


App Visibility

Control who can access your app in the app settings:

Public Apps

  • No login required for basic access
  • Users can view public content without authentication
  • Authenticated users get additional features/data

Private Apps

  • Login required to access any content
  • Unauthenticated users are automatically redirected to login
  • All content is protected by default

Limitations

Authentication UI Options

  • Recommended: Build custom login/signup UI using loginViaEmailPassword() and loginWithProvider() for full control over user experience and branding
  • Alternative: redirectToLogin() uses Base44’s hosted authentication pages with limited customization

Hosted Login (via redirectToLogin)

  • redirectToLogin() shows both login and signup options on the same page
  • No separate redirectToSignup() method
  • Users can switch between login/signup on the hosted page
  • ⚠️ Note: Prefer building custom login UI for better user experience

Password Requirements

  • Minimum length and complexity requirements enforced
  • Requirements not exposed via API
  • Validation errors returned when requirements not met

Rate Limiting

  • OTP requests are rate-limited to prevent abuse
  • Password reset requests are rate-limited
  • Login attempts may be rate-limited with Turnstile protection

Token Management

  • JWTs are automatically stored in localStorage by default
  • Token expiration and refresh not exposed in API
  • Call me() or isAuthenticated() to verify token validity

Best Practices

1. Always Handle Errors

2. Verify Authentication Before Protected Actions

3. Use Type Safety with TypeScript

4. Don’t Hardcode Credentials

5. Provide User Feedback

6. Handle Token Expiration Gracefully