Skip to content

[Bug]: base44.asServiceRole in base44 dev depends on caller Authorization instead of a real service token #491

@kaguya3222

Description

@kaguya3222

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

  1. 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 });
});
  1. Run npx base44 dev.
  2. Invoke the function without an Authorization header.
  3. Observe that base44.asServiceRole throws Service token is required to use asServiceRole. Please provide a serviceToken when creating the client.
  4. Invoke the same function with an Authorization: Bearer <user-token> header.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions