mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
Docker Emulator Test / docker (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Test / docker (push) Has been cancelled
Runs E2E API Tests / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
<!--
Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md
-->
<!-- ELLIPSIS_HIDDEN -->
----
> [!IMPORTANT]
> Adds redirect URL validation in sign-up process and updates test URL
to localhost.
>
> - **Behavior**:
> - Adds `validateRedirectUrl` check in `POST` handler in `route.tsx` to
ensure `verificationCallbackUrl` is whitelisted.
> - Throws `RedirectUrlNotWhitelisted` error if URL is not valid.
> - **Tests**:
> - Updates `verificationCallbackUrl` in `scaffoldProject` in
`js-helpers.ts` to `http://localhost:3000`.
>
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for f25e26b9d3. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>
<!-- ELLIPSIS_HIDDEN -->
---------
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { AdminProjectCreateOptions, StackAdminApp, StackClientApp, StackServerApp } from '@stackframe/js';
|
|
import { Result } from '@stackframe/stack-shared/dist/utils/results';
|
|
import { STACK_BACKEND_BASE_URL, STACK_INTERNAL_PROJECT_ADMIN_KEY, STACK_INTERNAL_PROJECT_CLIENT_KEY, STACK_INTERNAL_PROJECT_SERVER_KEY } from '../helpers';
|
|
|
|
export async function scaffoldProject(body?: Omit<AdminProjectCreateOptions, 'displayName'> & { displayName?: string }) {
|
|
const internalApp = new StackAdminApp({
|
|
projectId: 'internal',
|
|
baseUrl: STACK_BACKEND_BASE_URL,
|
|
publishableClientKey: STACK_INTERNAL_PROJECT_CLIENT_KEY,
|
|
secretServerKey: STACK_INTERNAL_PROJECT_SERVER_KEY,
|
|
superSecretAdminKey: STACK_INTERNAL_PROJECT_ADMIN_KEY,
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const fakeEmail = `${crypto.randomUUID()}@stack-js-test.example.com`;
|
|
|
|
Result.orThrow(await internalApp.signUpWithCredential({
|
|
email: fakeEmail,
|
|
password: "password",
|
|
verificationCallbackUrl: "http://localhost:3000",
|
|
}));
|
|
const adminUser = await internalApp.getUser({
|
|
or: 'throw',
|
|
});
|
|
|
|
const project = await adminUser.createProject({
|
|
displayName: body?.displayName || 'New Project',
|
|
...body,
|
|
});
|
|
|
|
return {
|
|
project,
|
|
adminUser,
|
|
};
|
|
}
|
|
|
|
export async function createApp(body?: Parameters<typeof scaffoldProject>[0]) {
|
|
const { project, adminUser } = await scaffoldProject(body);
|
|
const adminApp = new StackAdminApp({
|
|
projectId: project.id,
|
|
baseUrl: STACK_BACKEND_BASE_URL,
|
|
projectOwnerSession: adminUser._internalSession,
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const apiKey = await adminApp.createInternalApiKey({
|
|
description: 'test',
|
|
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
|
|
hasPublishableClientKey: true,
|
|
hasSecretServerKey: true,
|
|
hasSuperSecretAdminKey: false,
|
|
});
|
|
|
|
const serverApp = new StackServerApp({
|
|
baseUrl: STACK_BACKEND_BASE_URL,
|
|
projectId: project.id,
|
|
publishableClientKey: apiKey.publishableClientKey,
|
|
secretServerKey: apiKey.secretServerKey,
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const clientApp = new StackClientApp({
|
|
baseUrl: STACK_BACKEND_BASE_URL,
|
|
projectId: project.id,
|
|
publishableClientKey: apiKey.publishableClientKey,
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
return {
|
|
serverApp,
|
|
clientApp,
|
|
adminApp,
|
|
};
|
|
}
|