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

loginWithProvider()’s provider parameter is typed as a plain string in the SDK (not an exported union type), but these are the supported values:
  • 'google' — Google OAuth, enabled by default.
  • 'microsoft' — Microsoft OAuth, must enable in app auth settings.
  • 'facebook' — Facebook Login, must enable in app auth settings.
  • 'apple' — Sign in with Apple, must enable in app auth settings.
  • 'sso' — Enterprise SSO, must set up an SSO provider in app auth settings.

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

A 401 here automatically clears any token already stored on the client (the SDK calls logout() internally before rethrowing), so a failed login attempt never leaves a stale token behind.

Login with OAuth Provider

Supported providers: 'google' (enabled by default), 'microsoft', 'facebook', 'apple', and 'sso'. Enable Microsoft, Facebook, or Apple in your app’s authentication settings before using them; 'sso' requires setting up an SSO provider in app auth settings first.

Get Current User

Update User Profile

You can update custom fields defined in your User entity schema; field-level security write rules on custom fields apply here too — if data includes a field the user can’t write, the call throws and no fields are updated. These fields can never be changed with updateMe(): id, email, full_name, created_date, updated_date, created_by, collaborator_role. Changing role requires editor access on the app.

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

Check for a Token Without a Network Call

hasToken() only checks whether a token is set on the client — it doesn’t verify it’s still valid, and returns false for a session held only in an HTTP-only cookie. Use it to skip calls that can’t succeed anonymously; use isAuthenticated() when you need to confirm the session with the server.

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
  • Apple - Sign in with Apple
SSO Providers (Elite Plan):
  • Okta
  • Azure AD
  • GitHub
Use loginWithProvider('sso', fromUrl?) for enterprise SSO once a provider is configured in app auth settings.

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.
  • Apple – enable in your app’s authentication settings before use.
  • SSO – set up an SSO provider in your app’s authentication settings first.

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

Passwords must be at least 8 characters and at most 72 bytes. Emoji and non-English letters count as more than one byte. There’s no complexity requirement, so a password of only lowercase letters is accepted. If a password breaks either rule, the request fails with a validation error that says which one.

Rate Limiting

Registration, OTP, login, and password reset requests share one rate limit for each IP address. Requests over the limit fail with a rate-limit error. There’s no per-account lockout, so repeated failed logins for one account aren’t blocked unless they come from the same IP address. Each OTP code allows 5 attempts. The turnstileToken and turnstile_token parameters have no effect, because Base44 doesn’t verify Turnstile tokens for app users.

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