Description
In base44 dev, server functions created with createClientFromRequest(req) do not receive a distinct service-role credential.
For local function requests, the dev proxy copies the incoming Authorization header into Base44-Service-Authorization instead of providing a real service token. Because of that, base44.asServiceRole behaves differently from hosted Base44 environments:
- unauthenticated requests make
base44.asServiceRole throw because no service token is present
- authenticated requests make
base44.asServiceRole reuse the caller's user token rather than a true elevated service token
This makes code that works in hosted Base44 server functions fail or behave differently in local development.
Steps to Reproduce
- Create a server function that builds a client with
createClientFromRequest(req) and uses base44.asServiceRole, for example:
import { createClientFromRequest } from "npm:@base44/sdk";
Deno.serve(async (req) => {
const base44 = createClientFromRequest(req);
await base44.asServiceRole.entities.User.list();
return Response.json({ ok: true });
});
- Run
npx base44 dev.
- Invoke the function without an
Authorization header.
- Observe that
base44.asServiceRole throws Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.
- Invoke the same function with an
Authorization: Bearer <user-token> header.
- Observe that local dev forwards that same value as
Base44-Service-Authorization, so asServiceRole is driven by the caller token instead of a separate service credential.
Expected Behavior
base44.asServiceRole inside server functions should behave consistently between hosted Base44 and base44 dev.
Actual Behavior
In base44 dev:
- no service-role token is present for anonymous requests, so
base44.asServiceRole throws
- for authenticated requests,
Base44-Service-Authorization is derived from Authorization
- local behavior therefore differs from hosted Base44, where the same server-function code works with
base44.asServiceRole
Environment
- OS: macOS 26.3
- Node.js version: v22.17.0
- CLI version: 0.0.50
Error Logs
Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.
Additional Context
Relevant current implementation in base44/cli:
packages/cli/src/cli/dev/dev-server/routes/functions.ts sets Base44-Service-Authorization from the incoming Authorization header
packages/cli/tests/cli/dev.spec.ts has a test named forwards the service token header from Authorization to local functions
Relevant current behavior in @base44/sdk:
createClientFromRequest(req) reads Authorization and Base44-Service-Authorization separately
base44.asServiceRole throws when no serviceToken is present
Description
In
base44 dev, server functions created withcreateClientFromRequest(req)do not receive a distinct service-role credential.For local function requests, the dev proxy copies the incoming
Authorizationheader intoBase44-Service-Authorizationinstead of providing a real service token. Because of that,base44.asServiceRolebehaves differently from hosted Base44 environments:base44.asServiceRolethrow because no service token is presentbase44.asServiceRolereuse the caller's user token rather than a true elevated service tokenThis makes code that works in hosted Base44 server functions fail or behave differently in local development.
Steps to Reproduce
createClientFromRequest(req)and usesbase44.asServiceRole, for example:npx base44 dev.Authorizationheader.base44.asServiceRolethrowsService token is required to use asServiceRole. Please provide a serviceToken when creating the client.Authorization: Bearer <user-token>header.Base44-Service-Authorization, soasServiceRoleis driven by the caller token instead of a separate service credential.Expected Behavior
base44.asServiceRoleinside server functions should behave consistently between hosted Base44 andbase44 dev.Actual Behavior
In
base44 dev:base44.asServiceRolethrowsBase44-Service-Authorizationis derived fromAuthorizationbase44.asServiceRoleEnvironment
Error Logs
Additional Context
Relevant current implementation in
base44/cli:packages/cli/src/cli/dev/dev-server/routes/functions.tssetsBase44-Service-Authorizationfrom the incomingAuthorizationheaderpackages/cli/tests/cli/dev.spec.tshas a test namedforwards the service token header from Authorization to local functionsRelevant current behavior in
@base44/sdk:createClientFromRequest(req)readsAuthorizationandBase44-Service-Authorizationseparatelybase44.asServiceRolethrows when noserviceTokenis present