Organization auth
Supply a test organization token through mocked Global Config and exercise an organization-authenticated request
Supply an organization token through mocked Global Config, then exercise the application code that uses it. This tests server-side organization access, not a browser user’s session.
Before you start
Complete the Blueprint Auth tutorial. Your app’s SDK integration must use createGlobalConfigCacheAdapter from @krakentech/blueprint-auth/cache/global-config as its shared cache adapter.
The example assumes an /api/organization route that obtains organization auth with getAuth.org(), uses getGraphQLClient.org({ auth }) to run query OrganizationAuthProbe { __typename }, and returns { queryType: data.__typename }. Adapt the route, query, and response assertion to the organization-authenticated operation in your app.
Configure encryption and Global Config
Add a test-only encryption key to the shared testAuthConfig from the tutorial:
encryption: { key: "playwright_test_encryption_key" },Add these settings to webServer.env in your Playwright configuration. The app and fixture must use the same encryption key:
AUTH_ENCRYPTION_KEY: testAuthConfig.encryption.key,
GLOBAL_CONFIG: "https://global-config.vercel.com/test?token=test_config",
GLOBAL_CONFIG_DISABLE_DEVELOPMENT_SWR: "1",
VERCEL_AUTH_TOKEN: "playwright_test_token",
VERCEL_TEAM_ID: "playwright_test_team",The connection string, auth token, and team ID use dummy values. The cache adapter requires a nonempty auth token and team ID at construction, but this test reads the organization token supplied by the fixture. No real Vercel credentials are needed.
Disabling the development cache prevents cached values from leaking between tests. See Global Config application configuration for more context.
Compose the fixtures
Keep your existing createPlaywrightHelpers import, options, and exports. This change works with either MSW major. Add the withGlobalConfig import and replace the tutorial’s test extension so Global Config comes before Blueprint Auth:
import { withGlobalConfig } from "@octopus-energy/playwright/global-config";
const test = base.extend(withGlobalConfig()).extend(withBlueprintAuth(testAuthConfig));Keep this ordering whenever your auth config contains a nonempty encryption.key, even for tests that don’t request an organization token.
Exercise the application request
Register the organization token before triggering the application. Mock the requested GraphQL data separately, as you would for user-authenticated requests:
import { HttpResponse } from "msw";
import { expect, test } from "../../lib/playwright/test";
test("makes an organization-authenticated request", async ({ page, msw, blueprintAuth }) => {
await blueprintAuth.mock.organization({ subject: "test_organization" });
msw.use(
msw.graphql
.link("https://api.kraken.test/v1/graphql/")
.query("OrganizationAuthProbe", () => HttpResponse.json({ data: { __typename: "Query" } })),
);
const response = await page.goto("/api/organization");
expect(response?.ok()).toBe(true);
expect(await response?.json()).toEqual({ queryType: "Query" });
});The application reads the mocked token and uses its normal organization-authenticated client. No real Global Config writes are needed.