@@ -4,7 +4,6 @@ import { WorkOS } from "@workos-inc/node";
44// User configuration map - now keyed by email-password
55interface TestUser {
66 email : string ;
7- password : string ;
87 cookies ?: any [ ] ; // Cached cookies
98}
109
@@ -29,22 +28,20 @@ const COOKIE_DOMAIN = process.env.TEST_BASE_URL
2928
3029async function authenticateUser (
3130 email : string ,
32- password : string ,
3331 context : BrowserContext ,
3432) : Promise < void > {
35- if ( ! email || ! password ) {
33+ if ( ! email ) {
3634 throw new Error ( "Both email and password are required" ) ;
3735 }
3836
3937 // Create cache key from email and password
40- const cacheKey = `${ email } - ${ password } ` ;
38+ const cacheKey = `${ email } ` ;
4139 let user = userCache [ cacheKey ] ;
4240
4341 // Initialize user in cache if not exists
4442 if ( ! user ) {
4543 user = userCache [ cacheKey ] = {
4644 email,
47- password,
4845 } ;
4946 }
5047
@@ -71,11 +68,16 @@ async function authenticateUser(
7168 } ) ;
7269
7370 try {
71+ // create a magic auth token
72+ const magicAuthToken = await workos . userManagement . createMagicAuth ( {
73+ email,
74+ } ) ;
75+
7476 // Step 1: Get tokens from WorkOS API
75- const authResponse = await workos . userManagement . authenticateWithPassword ( {
77+ const authResponse = await workos . userManagement . authenticateWithMagicAuth ( {
7678 clientId : workosClientId ,
79+ code : magicAuthToken . code ,
7780 email,
78- password,
7981 session : {
8082 sealSession : true ,
8183 cookiePassword : process . env . WORKOS_COOKIE_PASSWORD ,
@@ -107,13 +109,12 @@ async function authenticateUser(
107109// Create extended test with email/password fixtures
108110export const test = base . extend < TestFixtures , WorkerFixtures > ( {
109111 email : [ undefined , { option : true } ] , // Email for authentication (optional)
110- password : [ undefined , { option : true } ] , // Password for authentication (optional)
111112
112113 // Override the default page fixture to handle authentication
113- page : async ( { page, email, password , context } , use ) => {
114- if ( email && password ) {
114+ page : async ( { page, email, context } , use ) => {
115+ if ( email ) {
115116 // Authenticate the user with email/password before providing the page
116- await authenticateUser ( email , password , context ) ;
117+ await authenticateUser ( email , context ) ;
117118 }
118119 // If email/password not provided, page remains unauthenticated
119120 await use ( page ) ;
0 commit comments