Auth Module
User authentication, registration, and session management viabase44.auth.
Contents
- TypeScript Types
- Methods
- Examples
- Error Handling
- Auth Providers
- Environment Availability
- App Visibility
- Limitations
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:- Register - Create the user account
- Verification email sent - User receives an OTP code
- Verify OTP - User enters code to verify email
- 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
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 — ifdata 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
- Okta
- Azure AD
- GitHub
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()andloginWithProvider()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. TheturnstileToken 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()orisAuthenticated()to verify token validity