@base44/sdk
Version:
JavaScript SDK for Base44 API
82 lines (81 loc) • 3.25 kB
TypeScript
import { AxiosInstance } from "axios";
/**
* Creates the auth module for the Base44 SDK
* @param {import('axios').AxiosInstance} axios - Axios instance
* @param {string|number} appId - Application ID
* @param {string} serverUrl - Server URL
* @returns {Object} Auth module with authentication methods
*/
export declare function createAuthModule(axios: AxiosInstance, functionsAxiosClient: AxiosInstance, appId: string, options: {
serverUrl: string;
appBaseUrl?: string;
}): {
/**
* Get current user information
* @returns {Promise<Object>} Current user data
*/
me(): Promise<import("axios").AxiosResponse<any, any>>;
/**
* Update current user data
* @param {Object} data - Updated user data
* @returns {Promise<Object>} Updated user
*/
updateMe(data: Record<string, any>): Promise<import("axios").AxiosResponse<any, any>>;
/**
* Redirects the user to the app's login page
* @param {string} nextUrl - URL to redirect to after successful login
* @throws {Error} When not in a browser environment
*/
redirectToLogin(nextUrl: string): void;
/**
* Logout the current user
* Removes the token from localStorage and optionally redirects to a URL or reloads the page
* @param redirectUrl - Optional URL to redirect to after logout. Reloads the page if not provided
* @returns {Promise<void>}
*/
logout(redirectUrl?: string): void;
/**
* Set authentication token
* @param {string} token - Auth token
* @param {boolean} [saveToStorage=true] - Whether to save the token to localStorage
*/
setToken(token: string, saveToStorage?: boolean): void;
/**
* Login via username and password
* @param email - User email
* @param password - User password
* @param turnstileToken - Optional Turnstile captcha token
* @returns Login response with access_token and user
*/
loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<{
access_token: string;
user: any;
}>;
/**
* Verify if the current token is valid
* @returns {Promise<boolean>} True if token is valid
*/
isAuthenticated(): Promise<boolean>;
inviteUser(userEmail: string, role: string): Promise<import("axios").AxiosResponse<any, any>>;
register(payload: {
email: string;
password: string;
turnstile_token?: string | null;
referral_code?: string | null;
}): Promise<import("axios").AxiosResponse<any, any>>;
verifyOtp({ email, otpCode }: {
email: string;
otpCode: string;
}): Promise<import("axios").AxiosResponse<any, any>>;
resendOtp(email: string): Promise<import("axios").AxiosResponse<any, any>>;
resetPasswordRequest(email: string): Promise<import("axios").AxiosResponse<any, any>>;
resetPassword({ resetToken, newPassword, }: {
resetToken: string;
newPassword: string;
}): Promise<import("axios").AxiosResponse<any, any>>;
changePassword({ userId, currentPassword, newPassword, }: {
userId: string;
currentPassword: string;
newPassword: string;
}): Promise<import("axios").AxiosResponse<any, any>>;
};