import { test as setup, expect } from '@playwright/test'; import path from 'path'; /** * Authentication setup for Playwright tests * * This file handles Auth0 login once and saves the authentication state * so we don't have to log in for every test. */ const authFile = path.join(__dirname, '../.auth/user.json'); setup('authenticate', async ({ page }) => { // For now, we'll skip actual Auth0 login since it requires real credentials // In production, you would: // 1. Go to login page // 2. Enter credentials // 3. Wait for redirect // 4. Save storage state // TODO: Implement actual Auth0 login when we have test credentials console.log('Auth setup skipped - implement with real credentials'); }); // Export helper function for tests that need authentication export async function login(page: any, email: string = 'test@example.com') { // This is a placeholder - implement actual Auth0 login flow await page.goto('/login'); // For local testing without Auth0, you can mock the authentication // by directly setting localStorage if (process.env.MOCK_AUTH === 'true') { await page.evaluate(() => { localStorage.setItem('auth0_token', 'mock-token'); localStorage.setItem( 'auth0_user', JSON.stringify({ email: 'test@example.com', name: 'Test User', role: 'ADMINISTRATOR', isApproved: true, }) ); }); await page.goto('/dashboard'); } }