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
Methods
Module Interface
Method Reference Table
| Method | Parameters | Return Type | Description |
|---|---|---|---|
register() | params: RegisterParams | Promise<any> | Create new user account |
loginViaEmailPassword() | email: string, password: string, turnstileToken?: string | Promise<LoginResponse> | Authenticate with email/password |
loginWithProvider() | provider: Provider, fromUrl?: string | void | Initiate OAuth login flow. Providers: 'google' (default), 'microsoft', 'facebook' (enable in app settings) |
me() | None | Promise<User> | Get current authenticated user |
updateMe() | data: Partial<User> | Promise<User> | Update current user’s profile |
logout() | redirectUrl?: string | void | Redirect to server-side logout (clears HTTP-only cookies and session), then to redirectUrl or current URL |
redirectToLogin() | nextUrl: string | void | ⚠️ Avoid - Prefer custom login UI with loginViaEmailPassword() or loginWithProvider() |
isAuthenticated() | None | Promise<boolean> | Check if user is logged in |
setToken() | token: string, saveToStorage?: boolean | void | Manually set auth token |
inviteUser() | userEmail: string, role: string | Promise<any> | Send invitation email |
verifyOtp() | params: VerifyOtpParams | Promise<any> | Verify OTP code |
resendOtp() | email: string | Promise<any> | Resend OTP code |
resetPasswordRequest() | email: string | Promise<any> | Request password reset |
resetPassword() | params: ResetPasswordParams | Promise<any> | Reset password with token |
changePassword() | params: ChangePasswordParams | Promise<any> | Change user password |
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
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
- 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
| Environment | Availability | Notes |
|---|---|---|
| Frontend | ✅ Yes | All methods available |
| Backend Functions | ✅ Yes | Use createClientFromRequest(req) for authenticated client |
| Service Role | ❌ No | Auth methods not available in service role context |
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
- 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()orisAuthenticated()to verify token validity

