Skip to content

Commit

Permalink
another test auth tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Irev-Dev committed Aug 15, 2024
1 parent 160abea commit b2254b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions e2e/playwright/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/machines/authMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -121,8 +122,8 @@ export const authMachine = createMachine<UserContext, Events>(
)

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)
Expand Down
8 changes: 7 additions & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b2254b1

Please sign in to comment.