The Base44 client is your interface to the Base44 SDK. It provides access to all SDK modules and automatically manages authentication tokens.You can use the client in two ways:
Inside Base44 apps: The client is automatically created and configured for you.
External apps: Create the client yourself to use Base44 as a backend for your own application.
In your frontend code, the client is already imported and available as base44.
Copy
Ask AI
import { base44 } from "@/api/base44Client";// The client is pre-configured and ready to useconst user = await base44.auth.me();const userTasks = await base44.entities.Task.filter({ assignedTo: user.id, status: "pending",});console.log(`${user.name} has ${userTasks.length} pending tasks`);
In Base44-hosted backend functions, create the client from the incoming request. Base44 injects the necessary authentication headers automatically.
Copy
Ask AI
import { createClientFromRequest } from "npm:@base44/sdk";Deno.serve(async (req) => { const base44 = createClientFromRequest(req); // Get the current user and their data const user = await base44.auth.me(); const userTasks = await base44.entities.Task.filter({ assignedTo: user.id, status: "pending", }); return Response.json({ user: user.name, pendingTasks: userTasks.length, });});
import { createClient } from "@base44/sdk";// Create a client for your Base44 appconst base44 = createClient({ appId: "your-app-id", // Find this in the Base44 editor URL});// Read public data (anonymous access)const products = await base44.entities.Products.list();
Authenticate users with email/password or other auth methods. The client automatically applies the token to subsequent requests.
Copy
Ask AI
import { createClient } from "@base44/sdk";const base44 = createClient({ appId: "your-app-id",});// Authenticate a user (token is automatically set)await base44.auth.loginViaEmailPassword("[email protected]", "password");// Now operations use the authenticated user's permissionsconst userOrders = await base44.entities.Orders.list();
By default, the client operates with user-level permissions, limiting access to what the current user can see and do. The service role provides elevated permissions for backend operations and is only available in Base44-hosted backend functions.
Service role authentication is only available in Base44-hosted backend
functions. External backends can’t use service role permissions.
A client with service role authentication allows backend code to:
Access data and operations with the same permissions as your app’s admin.
To use service role authentication, access modules through base44.asServiceRole instead of directly on the client. For example, base44.asServiceRole.entities.Task.list() operates with admin permissions, while base44.entities.Task.list() uses the current user’s permissions.When using createClientFromRequest() in a backend function, the service role is automatically available:
Copy
Ask AI
import { createClientFromRequest } from "npm:@base44/sdk";Deno.serve(async (req) => { const base44 = createClientFromRequest(req); // Access all data with admin-level permissions const allOrders = await base44.asServiceRole.entities.Orders.list(); return Response.json({ orders: allOrders });});