mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00

* feat(api): refresh token logic * feat(client): refresh token logic * feat(data-provider): refresh token logic * fix: SSE uses esm * chore: add default refresh token expiry to AuthService, add message about env var not set when generating a token * chore: update scripts to more compatible bun methods, ran bun install again * chore: update env.example and playwright workflow with JWT_REFRESH_SECRET * chore: update breaking changes docs * chore: add timeout to url visit * chore: add default SESSION_EXPIRY in generateToken logic, add act script for testing github actions * fix(e2e): refresh automatically in development environment to pass e2e tests
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { Page, FullConfig, chromium } from '@playwright/test';
|
|
import dotenv from 'dotenv';
|
|
dotenv.config();
|
|
|
|
type User = { username: string; password: string };
|
|
|
|
async function login(page: Page, user: User) {
|
|
await page.locator('input[name="email"]').fill(user.username);
|
|
await page.locator('input[name="password"]').fill(user.password);
|
|
await page.locator('input[name="password"]').press('Enter');
|
|
}
|
|
|
|
async function authenticate(config: FullConfig, user: User) {
|
|
console.log('🤖: global setup has been started');
|
|
const { baseURL, storageState } = config.projects[0].use;
|
|
console.log('🤖: using baseURL', baseURL);
|
|
console.dir(user, { depth: null });
|
|
const browser = await chromium.launch();
|
|
const page = await browser.newPage();
|
|
console.log('🤖: 🗝 authenticating user:', user.username);
|
|
|
|
if (!baseURL) {
|
|
throw new Error('🤖: baseURL is not defined');
|
|
}
|
|
await page.goto(baseURL, { timeout: 5000 });
|
|
await login(page, user);
|
|
await page.waitForURL(`${baseURL}/chat/new`);
|
|
console.log('🤖: ✔️ user successfully authenticated');
|
|
// Set localStorage before navigating to the page
|
|
await page.context().addInitScript(() => {
|
|
localStorage.setItem('navVisible', 'true');
|
|
});
|
|
console.log('🤖: ✔️ localStorage: set Nav as Visible', storageState);
|
|
await page.context().storageState({ path: storageState as string });
|
|
console.log('🤖: ✔️ authentication state successfully saved in', storageState);
|
|
await browser.close();
|
|
console.log('🤖: global setup has been finished');
|
|
}
|
|
|
|
export default authenticate;
|