mirror of
https://github.com/documenso/documenso.git
synced 2026-07-14 23:07:13 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
type LoginOptions = {
|
|
page: Page;
|
|
email?: string;
|
|
password?: string;
|
|
|
|
/**
|
|
* Where to navigate after login.
|
|
*/
|
|
redirectPath?: string;
|
|
};
|
|
|
|
export const apiSignin = async ({
|
|
page,
|
|
email = 'example@documenso.com',
|
|
password = 'password',
|
|
redirectPath = '/',
|
|
}: LoginOptions) => {
|
|
const { request } = page.context();
|
|
|
|
const csrfToken = await getCsrfToken(page);
|
|
|
|
await request.post(`${NEXT_PUBLIC_WEBAPP_URL()}/api/auth/email-password/authorize`, {
|
|
data: {
|
|
email,
|
|
password,
|
|
csrfToken,
|
|
},
|
|
});
|
|
|
|
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}${redirectPath}`);
|
|
await page.waitForTimeout(500);
|
|
};
|
|
|
|
export const apiSignout = async ({ page }: { page: Page }) => {
|
|
const { request } = page.context();
|
|
|
|
await request.post(`${NEXT_PUBLIC_WEBAPP_URL()}/api/auth/signout`);
|
|
|
|
await page.goto(`${NEXT_PUBLIC_WEBAPP_URL()}/signin`);
|
|
};
|
|
|
|
const getCsrfToken = async (page: Page) => {
|
|
const { request } = page.context();
|
|
|
|
const response = await request.fetch(`${NEXT_PUBLIC_WEBAPP_URL()}/api/auth/csrf`, {
|
|
method: 'get',
|
|
});
|
|
|
|
const { csrfToken } = await response.json();
|
|
|
|
if (!csrfToken) {
|
|
throw new Error('Invalid session');
|
|
}
|
|
|
|
return csrfToken;
|
|
};
|
|
|
|
export const checkSessionValid = async (page: Page): Promise<boolean> => {
|
|
const { request } = page.context();
|
|
|
|
const response = await request.fetch(`${NEXT_PUBLIC_WEBAPP_URL()}/api/auth/session`, {
|
|
method: 'get',
|
|
});
|
|
|
|
const session = await response.json();
|
|
|
|
return session.isAuthenticated === true;
|
|
};
|