import '@testing-library/cypress/add-commands' ; import { Session } from 'next-auth' ; import { defaultCookies } from '../../src/server/utilities/default-cookies' ; import { jwtBody } from '../fixtures/user' ; const cookieOptions = defaultCookies ( Cypress . config ( ) . baseUrl . startsWith ( 'https' ) ) . sessionToken ; const cookieName = cookieOptions . name ; Cypress . Commands . add ( 'login' , ( ) => { cy . intercept ( `/api/auth/session` , ( req ) => { req . continue ( ( res ) => { res . send ( { body : { ... jwtBody , hasuraToken : Cypress . env ( 'HASURA_TOKEN' ) , } as Session , } ) ; } ) ; } ) . as ( 'session' ) ; cy . intercept ( '/v1/graphql' ) . as ( 'graphql' ) ; cy . setCookie ( cookieName , Cypress . env ( 'SESSION_TOKEN' ) , { httpOnly : cookieOptions . options . httpOnly , secure : cookieOptions . options . secure , sameSite : cookieOptions . options . sameSite as 'lax' , } ) ; Cypress . Cookies . preserveOnce ( cookieName ) ; } ) ;