stack/apps/e2e/tests/js/inheritance.test.ts
BilalG1 48295825eb
fix default redirect method (#1253)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Adjusted internal default selection for redirect handling to improve
consistency; no change to user-facing behavior or settings.
* **Tests**
* Updated end-to-end tests and helpers to explicitly set redirect
behavior so test runs remain deterministic.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-03-31 15:08:33 -07:00

92 lines
3.0 KiB
TypeScript

import { StackAdminApp, StackClientApp, StackServerApp } from "@stackframe/js";
import { throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { isUuid } from "@stackframe/stack-shared/dist/utils/uuids";
import { STACK_BACKEND_BASE_URL, it } from "../helpers";
import { scaffoldProject } from "./js-helpers";
it("StackServerApp can inherit configuration from StackClientApp", async ({ expect }) => {
const { project, adminUser } = await scaffoldProject();
const adminApp = new StackAdminApp({
projectId: project.id,
baseUrl: STACK_BACKEND_BASE_URL,
projectOwnerSession: adminUser._internalSession,
tokenStore: "memory",
redirectMethod: "none",
});
const key = await adminApp.createInternalApiKey({
description: "inheritance test key",
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
hasPublishableClientKey: true,
hasSecretServerKey: true,
hasSuperSecretAdminKey: true,
});
const clientApp = new StackClientApp({
baseUrl: STACK_BACKEND_BASE_URL,
projectId: project.id,
publishableClientKey: key.publishableClientKey,
tokenStore: "memory",
redirectMethod: "none",
});
const serverApp = new StackServerApp({
inheritsFrom: clientApp,
secretServerKey: key.secretServerKey,
tokenStore: "memory",
});
const createdUser = await serverApp.createUser({
primaryEmail: `${crypto.randomUUID()}@inheritance-test.example.com`,
password: "password",
primaryEmailAuthEnabled: true,
});
expect(isUuid(createdUser.id)).toBe(true);
const fetchedUser = await serverApp.getUser(createdUser.id);
expect(fetchedUser?.id).toBe(createdUser.id);
});
it("StackAdminApp can inherit configuration from StackServerApp", async ({ expect }) => {
const { project, adminUser } = await scaffoldProject();
const adminApp = new StackAdminApp({
projectId: project.id,
baseUrl: STACK_BACKEND_BASE_URL,
projectOwnerSession: adminUser._internalSession,
tokenStore: "memory",
redirectMethod: "none",
});
const key = await adminApp.createInternalApiKey({
description: "admin inheritance key",
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
hasPublishableClientKey: true,
hasSecretServerKey: true,
hasSuperSecretAdminKey: true,
});
const clientApp = new StackClientApp({
baseUrl: STACK_BACKEND_BASE_URL,
projectId: project.id,
publishableClientKey: key.publishableClientKey,
tokenStore: "memory",
redirectMethod: "none",
});
const serverApp = new StackServerApp({
inheritsFrom: clientApp,
secretServerKey: key.secretServerKey ?? throwErr("secret server key missing"),
tokenStore: "memory",
});
const adminInherited = new StackAdminApp({
inheritsFrom: serverApp,
superSecretAdminKey: key.superSecretAdminKey ?? throwErr("super secret admin key missing"),
tokenStore: "memory",
});
const keys = await adminInherited.listInternalApiKeys();
expect(Array.isArray(keys)).toBe(true);
expect(adminInherited.projectId).toBe(project.id);
});