From b2254b10af6d706d6b03b4c68e60d917834eb81d Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Thu, 15 Aug 2024 18:11:40 +1000 Subject: [PATCH] another test auth tweak --- e2e/playwright/test-utils.ts | 2 ++ interface.d.ts | 2 ++ src/machines/authMachine.ts | 7 ++++--- src/preload.ts | 8 +++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/e2e/playwright/test-utils.ts b/e2e/playwright/test-utils.ts index 9256ab5a8..942f53e83 100644 --- a/e2e/playwright/test-utils.ts +++ b/e2e/playwright/test-utils.ts @@ -688,6 +688,8 @@ export async function setupElectron({ ...process.env, TEST_SETTINGS_FILE_KEY: projectDirName, IS_PLAYWRIGHT: 'true', + SKIP_AUTH: 'true', + DEV_TOKEN: secrets.token, }, }) const context = electronApp.context() diff --git a/interface.d.ts b/interface.d.ts index 698894824..1a6c72c89 100644 --- a/interface.d.ts +++ b/interface.d.ts @@ -37,6 +37,8 @@ export interface IElectronAPI { BASE_URL: EnvFn TEST_SETTINGS_FILE_KEY: EnvFn IS_PLAYWRIGHT: EnvFn + SKIP_AUTH: EnvFn + DEV_TOKEN: EnvFn } } kittycad: (access: string, args: any) => any diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 7512712e6..9926e2757 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -8,7 +8,8 @@ import { COOKIE_NAME } from 'lib/constants' const SKIP_AUTH = // @ts-ignore - import.meta.env.VITE_KC_SKIP_AUTH === 'true' && import.meta.env.DEV + (import.meta.env.VITE_KC_SKIP_AUTH === 'true' && import.meta.env.DEV) || + window.electron.process.env.SKIP_AUTH() const LOCAL_USER: Models['User_type'] = { id: '8675309', @@ -121,8 +122,8 @@ export const authMachine = createMachine( ) async function getUser(context: UserContext) { - const token = VITE_KC_DEV_TOKEN - ? VITE_KC_DEV_TOKEN + const token = VITE_KC_DEV_TOKEN || window.electron.process.env.DEV_TOKEN() + ? VITE_KC_DEV_TOKEN || window.electron.process.env.DEV_TOKEN() : context.token && context.token !== '' ? context.token : getCookie(COOKIE_NAME) || localStorage?.getItem(TOKEN_PERSIST_KEY) diff --git a/src/preload.ts b/src/preload.ts index 46f7480be..31330124e 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -86,7 +86,13 @@ contextBridge.exposeInMainWorld('electron', { // these are read-only over the boundary. env: Object.assign( {}, - exposeProcessEnvs(['BASE_URL', 'TEST_SETTINGS_FILE_KEY', 'IS_PLAYWRIGHT']) + exposeProcessEnvs([ + 'BASE_URL', + 'TEST_SETTINGS_FILE_KEY', + 'IS_PLAYWRIGHT', + 'SKIP_AUTH', + 'DEV_TOKEN', + ]) ), }, kittycad,